@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\services\database\TableAnalysis; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | /** |
8 | 8 | * the purpose of this file is to simply contain any action/filter hook callbacks etc for specific aspects of EE |
@@ -27,277 +27,277 @@ discard block |
||
27 | 27 | class EE_Brewing_Regular extends EE_BASE |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
32 | - */ |
|
33 | - protected $_table_analysis; |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * EE_Brewing_Regular constructor. |
|
39 | - */ |
|
40 | - public function __construct(TableAnalysis $table_analysis) |
|
41 | - { |
|
42 | - $this->_table_analysis = $table_analysis; |
|
43 | - if (defined('EE_CAFF_PATH')) { |
|
44 | - // activation |
|
45 | - add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content')); |
|
46 | - // load caff init |
|
47 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init')); |
|
48 | - // remove the "powered by" credit link from receipts and invoices |
|
49 | - add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
50 | - // add caffeinated modules |
|
51 | - add_filter( |
|
52 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
53 | - array($this, 'caffeinated_modules_to_register') |
|
54 | - ); |
|
55 | - // load caff scripts |
|
56 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10); |
|
57 | - add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
58 | - add_filter( |
|
59 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
60 | - array($this, 'caf_payment_methods') |
|
61 | - ); |
|
62 | - // caffeinated constructed |
|
63 | - do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
64 | - //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
65 | - add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
66 | - } |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
73 | - * |
|
74 | - * @param array $paths original helper paths array |
|
75 | - * @return array new array of paths |
|
76 | - */ |
|
77 | - public function caf_helper_paths($paths) |
|
78 | - { |
|
79 | - $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
80 | - return $paths; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
87 | - * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
88 | - * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
89 | - * This action should only be called when EE 4.x.0.P is initially activated. |
|
90 | - * Right now the only CAF content are these global prices. If there's more in the future, then |
|
91 | - * we should probably create a caf file to contain it all instead just a function like this. |
|
92 | - * Right now, we ASSUME the only price types in the system are default ones |
|
93 | - * |
|
94 | - * @global wpdb $wpdb |
|
95 | - */ |
|
96 | - public function initialize_caf_db_content() |
|
97 | - { |
|
98 | - global $wpdb; |
|
99 | - //use same method of getting creator id as the version introducing the change |
|
100 | - $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
101 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
102 | - $price_table = $wpdb->prefix . "esp_price"; |
|
103 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
104 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types |
|
105 | - $tax_price_type_count = $wpdb->get_var($SQL); |
|
106 | - if ($tax_price_type_count <= 1) { |
|
107 | - $wpdb->insert( |
|
108 | - $price_type_table, |
|
109 | - array( |
|
110 | - 'PRT_name' => __("Regional Tax", "event_espresso"), |
|
111 | - 'PBT_ID' => 4, |
|
112 | - 'PRT_is_percent' => true, |
|
113 | - 'PRT_order' => 60, |
|
114 | - 'PRT_deleted' => false, |
|
115 | - 'PRT_wp_user' => $default_creator_id, |
|
116 | - ), |
|
117 | - array( |
|
118 | - '%s',//PRT_name |
|
119 | - '%d',//PBT_id |
|
120 | - '%d',//PRT_is_percent |
|
121 | - '%d',//PRT_order |
|
122 | - '%d',//PRT_deleted |
|
123 | - '%d', //PRT_wp_user |
|
124 | - ) |
|
125 | - ); |
|
126 | - //federal tax |
|
127 | - $result = $wpdb->insert( |
|
128 | - $price_type_table, |
|
129 | - array( |
|
130 | - 'PRT_name' => __("Federal Tax", "event_espresso"), |
|
131 | - 'PBT_ID' => 4, |
|
132 | - 'PRT_is_percent' => true, |
|
133 | - 'PRT_order' => 70, |
|
134 | - 'PRT_deleted' => false, |
|
135 | - 'PRT_wp_user' => $default_creator_id, |
|
136 | - ), |
|
137 | - array( |
|
138 | - '%s',//PRT_name |
|
139 | - '%d',//PBT_id |
|
140 | - '%d',//PRT_is_percent |
|
141 | - '%d',//PRT_order |
|
142 | - '%d',//PRT_deleted |
|
143 | - '%d' //PRT_wp_user |
|
144 | - ) |
|
145 | - ); |
|
146 | - if ($result) { |
|
147 | - $wpdb->insert( |
|
148 | - $price_table, |
|
149 | - array( |
|
150 | - 'PRT_ID' => $wpdb->insert_id, |
|
151 | - 'PRC_amount' => 15.00, |
|
152 | - 'PRC_name' => __("Sales Tax", "event_espresso"), |
|
153 | - 'PRC_desc' => '', |
|
154 | - 'PRC_is_default' => true, |
|
155 | - 'PRC_overrides' => null, |
|
156 | - 'PRC_deleted' => false, |
|
157 | - 'PRC_order' => 50, |
|
158 | - 'PRC_parent' => null, |
|
159 | - 'PRC_wp_user' => $default_creator_id, |
|
160 | - ), |
|
161 | - array( |
|
162 | - '%d',//PRT_id |
|
163 | - '%f',//PRC_amount |
|
164 | - '%s',//PRC_name |
|
165 | - '%s',//PRC_desc |
|
166 | - '%d',//PRC_is_default |
|
167 | - '%d',//PRC_overrides |
|
168 | - '%d',//PRC_deleted |
|
169 | - '%d',//PRC_order |
|
170 | - '%d',//PRC_parent |
|
171 | - '%d' //PRC_wp_user |
|
172 | - ) |
|
173 | - ); |
|
174 | - } |
|
175 | - } |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * caffeinated_modules_to_register |
|
183 | - * |
|
184 | - * @access public |
|
185 | - * @param array $modules_to_register |
|
186 | - * @return array |
|
187 | - */ |
|
188 | - public function caffeinated_modules_to_register($modules_to_register = array()) |
|
189 | - { |
|
190 | - if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
191 | - $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
192 | - if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
193 | - $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
194 | - } |
|
195 | - } |
|
196 | - return $modules_to_register; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - public function caffeinated_init() |
|
202 | - { |
|
203 | - // EE_Register_CPTs hooks |
|
204 | - add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10); |
|
205 | - add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10); |
|
206 | - add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10); |
|
207 | - EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false); |
|
208 | - // caffeinated_init__complete hook |
|
209 | - do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - public function enqueue_caffeinated_scripts() |
|
215 | - { |
|
216 | - // sound of crickets... |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * callbacks below here |
|
223 | - * |
|
224 | - * @param array $taxonomy_array |
|
225 | - * @return array |
|
226 | - */ |
|
227 | - public function filter_taxonomies(array $taxonomy_array) |
|
228 | - { |
|
229 | - $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
230 | - return $taxonomy_array; |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * @param array $cpt_array |
|
237 | - * @return mixed |
|
238 | - */ |
|
239 | - public function filter_cpts(array $cpt_array) |
|
240 | - { |
|
241 | - $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
242 | - return $cpt_array; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * @param array $menuitems |
|
249 | - * @return array |
|
250 | - */ |
|
251 | - public function nav_metabox_items(array $menuitems) |
|
252 | - { |
|
253 | - $menuitems[] = array( |
|
254 | - 'title' => __('Venue List', 'event_espresso'), |
|
255 | - 'url' => get_post_type_archive_link('espresso_venues'), |
|
256 | - 'description' => __('Archive page for all venues.', 'event_espresso'), |
|
257 | - ); |
|
258 | - return $menuitems; |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods |
|
265 | - * |
|
266 | - * @param array $payment_method_paths |
|
267 | - * @return array values are folder paths to payment method folders |
|
268 | - */ |
|
269 | - public function caf_payment_methods($payment_method_paths) |
|
270 | - { |
|
271 | - $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
272 | - $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths); |
|
273 | - return $payment_method_paths; |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * Gets the injected table analyzer, or throws an exception |
|
280 | - * |
|
281 | - * @return TableAnalysis |
|
282 | - * @throws \EE_Error |
|
283 | - */ |
|
284 | - protected function _get_table_analysis() |
|
285 | - { |
|
286 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
287 | - return $this->_table_analysis; |
|
288 | - } else { |
|
289 | - throw new \EE_Error( |
|
290 | - sprintf( |
|
291 | - __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
292 | - get_class($this) |
|
293 | - ) |
|
294 | - ); |
|
295 | - } |
|
296 | - } |
|
30 | + /** |
|
31 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
32 | + */ |
|
33 | + protected $_table_analysis; |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * EE_Brewing_Regular constructor. |
|
39 | + */ |
|
40 | + public function __construct(TableAnalysis $table_analysis) |
|
41 | + { |
|
42 | + $this->_table_analysis = $table_analysis; |
|
43 | + if (defined('EE_CAFF_PATH')) { |
|
44 | + // activation |
|
45 | + add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content')); |
|
46 | + // load caff init |
|
47 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init')); |
|
48 | + // remove the "powered by" credit link from receipts and invoices |
|
49 | + add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
50 | + // add caffeinated modules |
|
51 | + add_filter( |
|
52 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
53 | + array($this, 'caffeinated_modules_to_register') |
|
54 | + ); |
|
55 | + // load caff scripts |
|
56 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10); |
|
57 | + add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
58 | + add_filter( |
|
59 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
60 | + array($this, 'caf_payment_methods') |
|
61 | + ); |
|
62 | + // caffeinated constructed |
|
63 | + do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
64 | + //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
65 | + add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
66 | + } |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
73 | + * |
|
74 | + * @param array $paths original helper paths array |
|
75 | + * @return array new array of paths |
|
76 | + */ |
|
77 | + public function caf_helper_paths($paths) |
|
78 | + { |
|
79 | + $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
80 | + return $paths; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
87 | + * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
88 | + * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
89 | + * This action should only be called when EE 4.x.0.P is initially activated. |
|
90 | + * Right now the only CAF content are these global prices. If there's more in the future, then |
|
91 | + * we should probably create a caf file to contain it all instead just a function like this. |
|
92 | + * Right now, we ASSUME the only price types in the system are default ones |
|
93 | + * |
|
94 | + * @global wpdb $wpdb |
|
95 | + */ |
|
96 | + public function initialize_caf_db_content() |
|
97 | + { |
|
98 | + global $wpdb; |
|
99 | + //use same method of getting creator id as the version introducing the change |
|
100 | + $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
101 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
102 | + $price_table = $wpdb->prefix . "esp_price"; |
|
103 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
104 | + $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types |
|
105 | + $tax_price_type_count = $wpdb->get_var($SQL); |
|
106 | + if ($tax_price_type_count <= 1) { |
|
107 | + $wpdb->insert( |
|
108 | + $price_type_table, |
|
109 | + array( |
|
110 | + 'PRT_name' => __("Regional Tax", "event_espresso"), |
|
111 | + 'PBT_ID' => 4, |
|
112 | + 'PRT_is_percent' => true, |
|
113 | + 'PRT_order' => 60, |
|
114 | + 'PRT_deleted' => false, |
|
115 | + 'PRT_wp_user' => $default_creator_id, |
|
116 | + ), |
|
117 | + array( |
|
118 | + '%s',//PRT_name |
|
119 | + '%d',//PBT_id |
|
120 | + '%d',//PRT_is_percent |
|
121 | + '%d',//PRT_order |
|
122 | + '%d',//PRT_deleted |
|
123 | + '%d', //PRT_wp_user |
|
124 | + ) |
|
125 | + ); |
|
126 | + //federal tax |
|
127 | + $result = $wpdb->insert( |
|
128 | + $price_type_table, |
|
129 | + array( |
|
130 | + 'PRT_name' => __("Federal Tax", "event_espresso"), |
|
131 | + 'PBT_ID' => 4, |
|
132 | + 'PRT_is_percent' => true, |
|
133 | + 'PRT_order' => 70, |
|
134 | + 'PRT_deleted' => false, |
|
135 | + 'PRT_wp_user' => $default_creator_id, |
|
136 | + ), |
|
137 | + array( |
|
138 | + '%s',//PRT_name |
|
139 | + '%d',//PBT_id |
|
140 | + '%d',//PRT_is_percent |
|
141 | + '%d',//PRT_order |
|
142 | + '%d',//PRT_deleted |
|
143 | + '%d' //PRT_wp_user |
|
144 | + ) |
|
145 | + ); |
|
146 | + if ($result) { |
|
147 | + $wpdb->insert( |
|
148 | + $price_table, |
|
149 | + array( |
|
150 | + 'PRT_ID' => $wpdb->insert_id, |
|
151 | + 'PRC_amount' => 15.00, |
|
152 | + 'PRC_name' => __("Sales Tax", "event_espresso"), |
|
153 | + 'PRC_desc' => '', |
|
154 | + 'PRC_is_default' => true, |
|
155 | + 'PRC_overrides' => null, |
|
156 | + 'PRC_deleted' => false, |
|
157 | + 'PRC_order' => 50, |
|
158 | + 'PRC_parent' => null, |
|
159 | + 'PRC_wp_user' => $default_creator_id, |
|
160 | + ), |
|
161 | + array( |
|
162 | + '%d',//PRT_id |
|
163 | + '%f',//PRC_amount |
|
164 | + '%s',//PRC_name |
|
165 | + '%s',//PRC_desc |
|
166 | + '%d',//PRC_is_default |
|
167 | + '%d',//PRC_overrides |
|
168 | + '%d',//PRC_deleted |
|
169 | + '%d',//PRC_order |
|
170 | + '%d',//PRC_parent |
|
171 | + '%d' //PRC_wp_user |
|
172 | + ) |
|
173 | + ); |
|
174 | + } |
|
175 | + } |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * caffeinated_modules_to_register |
|
183 | + * |
|
184 | + * @access public |
|
185 | + * @param array $modules_to_register |
|
186 | + * @return array |
|
187 | + */ |
|
188 | + public function caffeinated_modules_to_register($modules_to_register = array()) |
|
189 | + { |
|
190 | + if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
191 | + $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
192 | + if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
193 | + $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
194 | + } |
|
195 | + } |
|
196 | + return $modules_to_register; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + public function caffeinated_init() |
|
202 | + { |
|
203 | + // EE_Register_CPTs hooks |
|
204 | + add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10); |
|
205 | + add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10); |
|
206 | + add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10); |
|
207 | + EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false); |
|
208 | + // caffeinated_init__complete hook |
|
209 | + do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + public function enqueue_caffeinated_scripts() |
|
215 | + { |
|
216 | + // sound of crickets... |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * callbacks below here |
|
223 | + * |
|
224 | + * @param array $taxonomy_array |
|
225 | + * @return array |
|
226 | + */ |
|
227 | + public function filter_taxonomies(array $taxonomy_array) |
|
228 | + { |
|
229 | + $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
230 | + return $taxonomy_array; |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * @param array $cpt_array |
|
237 | + * @return mixed |
|
238 | + */ |
|
239 | + public function filter_cpts(array $cpt_array) |
|
240 | + { |
|
241 | + $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
242 | + return $cpt_array; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * @param array $menuitems |
|
249 | + * @return array |
|
250 | + */ |
|
251 | + public function nav_metabox_items(array $menuitems) |
|
252 | + { |
|
253 | + $menuitems[] = array( |
|
254 | + 'title' => __('Venue List', 'event_espresso'), |
|
255 | + 'url' => get_post_type_archive_link('espresso_venues'), |
|
256 | + 'description' => __('Archive page for all venues.', 'event_espresso'), |
|
257 | + ); |
|
258 | + return $menuitems; |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods |
|
265 | + * |
|
266 | + * @param array $payment_method_paths |
|
267 | + * @return array values are folder paths to payment method folders |
|
268 | + */ |
|
269 | + public function caf_payment_methods($payment_method_paths) |
|
270 | + { |
|
271 | + $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
272 | + $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths); |
|
273 | + return $payment_method_paths; |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * Gets the injected table analyzer, or throws an exception |
|
280 | + * |
|
281 | + * @return TableAnalysis |
|
282 | + * @throws \EE_Error |
|
283 | + */ |
|
284 | + protected function _get_table_analysis() |
|
285 | + { |
|
286 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
287 | + return $this->_table_analysis; |
|
288 | + } else { |
|
289 | + throw new \EE_Error( |
|
290 | + sprintf( |
|
291 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
292 | + get_class($this) |
|
293 | + ) |
|
294 | + ); |
|
295 | + } |
|
296 | + } |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | |
300 | 300 | |
301 | 301 | $brewing = new EE_Brewing_Regular( |
302 | - EE_Registry::instance()->create('TableAnalysis', array(), true) |
|
302 | + EE_Registry::instance()->create('TableAnalysis', array(), true) |
|
303 | 303 | ); |
@@ -10,10 +10,10 @@ discard block |
||
10 | 10 | * define and use the hook in a specific caffeinated/whatever class or file. |
11 | 11 | */ |
12 | 12 | // defined some new constants related to caffeinated folder |
13 | -define('EE_CAF_URL', EE_PLUGIN_DIR_URL . 'caffeinated/'); |
|
14 | -define('EE_CAF_CORE', EE_CAFF_PATH . 'core' . DS); |
|
15 | -define('EE_CAF_LIBRARIES', EE_CAF_CORE . 'libraries' . DS); |
|
16 | -define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH . 'payment_methods' . DS); |
|
13 | +define('EE_CAF_URL', EE_PLUGIN_DIR_URL.'caffeinated/'); |
|
14 | +define('EE_CAF_CORE', EE_CAFF_PATH.'core'.DS); |
|
15 | +define('EE_CAF_LIBRARIES', EE_CAF_CORE.'libraries'.DS); |
|
16 | +define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH.'payment_methods'.DS); |
|
17 | 17 | |
18 | 18 | |
19 | 19 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function caf_helper_paths($paths) |
78 | 78 | { |
79 | - $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
79 | + $paths[] = EE_CAF_CORE.'helpers'.DS; |
|
80 | 80 | return $paths; |
81 | 81 | } |
82 | 82 | |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | global $wpdb; |
99 | 99 | //use same method of getting creator id as the version introducing the change |
100 | 100 | $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
101 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
102 | - $price_table = $wpdb->prefix . "esp_price"; |
|
101 | + $price_type_table = $wpdb->prefix."esp_price_type"; |
|
102 | + $price_table = $wpdb->prefix."esp_price"; |
|
103 | 103 | if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
104 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types |
|
104 | + $SQL = 'SELECT COUNT(PRT_ID) FROM '.$price_type_table.' WHERE PBT_ID=4'; //include trashed price types |
|
105 | 105 | $tax_price_type_count = $wpdb->get_var($SQL); |
106 | 106 | if ($tax_price_type_count <= 1) { |
107 | 107 | $wpdb->insert( |
@@ -115,11 +115,11 @@ discard block |
||
115 | 115 | 'PRT_wp_user' => $default_creator_id, |
116 | 116 | ), |
117 | 117 | array( |
118 | - '%s',//PRT_name |
|
119 | - '%d',//PBT_id |
|
120 | - '%d',//PRT_is_percent |
|
121 | - '%d',//PRT_order |
|
122 | - '%d',//PRT_deleted |
|
118 | + '%s', //PRT_name |
|
119 | + '%d', //PBT_id |
|
120 | + '%d', //PRT_is_percent |
|
121 | + '%d', //PRT_order |
|
122 | + '%d', //PRT_deleted |
|
123 | 123 | '%d', //PRT_wp_user |
124 | 124 | ) |
125 | 125 | ); |
@@ -135,11 +135,11 @@ discard block |
||
135 | 135 | 'PRT_wp_user' => $default_creator_id, |
136 | 136 | ), |
137 | 137 | array( |
138 | - '%s',//PRT_name |
|
139 | - '%d',//PBT_id |
|
140 | - '%d',//PRT_is_percent |
|
141 | - '%d',//PRT_order |
|
142 | - '%d',//PRT_deleted |
|
138 | + '%s', //PRT_name |
|
139 | + '%d', //PBT_id |
|
140 | + '%d', //PRT_is_percent |
|
141 | + '%d', //PRT_order |
|
142 | + '%d', //PRT_deleted |
|
143 | 143 | '%d' //PRT_wp_user |
144 | 144 | ) |
145 | 145 | ); |
@@ -159,15 +159,15 @@ discard block |
||
159 | 159 | 'PRC_wp_user' => $default_creator_id, |
160 | 160 | ), |
161 | 161 | array( |
162 | - '%d',//PRT_id |
|
163 | - '%f',//PRC_amount |
|
164 | - '%s',//PRC_name |
|
165 | - '%s',//PRC_desc |
|
166 | - '%d',//PRC_is_default |
|
167 | - '%d',//PRC_overrides |
|
168 | - '%d',//PRC_deleted |
|
169 | - '%d',//PRC_order |
|
170 | - '%d',//PRC_parent |
|
162 | + '%d', //PRT_id |
|
163 | + '%f', //PRC_amount |
|
164 | + '%s', //PRC_name |
|
165 | + '%s', //PRC_desc |
|
166 | + '%d', //PRC_is_default |
|
167 | + '%d', //PRC_overrides |
|
168 | + '%d', //PRC_deleted |
|
169 | + '%d', //PRC_order |
|
170 | + '%d', //PRC_parent |
|
171 | 171 | '%d' //PRC_wp_user |
172 | 172 | ) |
173 | 173 | ); |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function caffeinated_modules_to_register($modules_to_register = array()) |
189 | 189 | { |
190 | - if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
191 | - $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
190 | + if (is_readable(EE_CAFF_PATH.'modules')) { |
|
191 | + $caffeinated_modules_to_register = glob(EE_CAFF_PATH.'modules'.DS.'*', GLOB_ONLYDIR); |
|
192 | 192 | if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
193 | 193 | $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
194 | 194 | } |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | */ |
269 | 269 | public function caf_payment_methods($payment_method_paths) |
270 | 270 | { |
271 | - $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
271 | + $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS.'*', GLOB_ONLYDIR); |
|
272 | 272 | $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths); |
273 | 273 | return $payment_method_paths; |
274 | 274 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -15,231 +15,231 @@ discard block |
||
15 | 15 | class EE_Request |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @access private |
|
20 | - * @var array $_get $_GET parameters |
|
21 | - */ |
|
22 | - private $_get = array(); |
|
23 | - |
|
24 | - /** |
|
25 | - * @access private |
|
26 | - * @var array $_post $_POST parameters |
|
27 | - */ |
|
28 | - private $_post = array(); |
|
29 | - |
|
30 | - /** |
|
31 | - * @access private |
|
32 | - * @var array $_cookie $_COOKIE parameters |
|
33 | - */ |
|
34 | - private $_cookie = array(); |
|
35 | - |
|
36 | - /** |
|
37 | - * @access private |
|
38 | - * @var array $_params $_REQUEST parameters |
|
39 | - */ |
|
40 | - private $_params = array(); |
|
41 | - |
|
42 | - /** |
|
43 | - * whether current request is via AJAX |
|
44 | - * |
|
45 | - * @var boolean |
|
46 | - * @access public |
|
47 | - */ |
|
48 | - public $ajax = false; |
|
49 | - |
|
50 | - /** |
|
51 | - * whether current request is via AJAX from the frontend of the site |
|
52 | - * |
|
53 | - * @var boolean |
|
54 | - * @access public |
|
55 | - */ |
|
56 | - public $front_ajax = false; |
|
57 | - |
|
58 | - /** |
|
59 | - * IP address for request |
|
60 | - * |
|
61 | - * @var string $_ip_address |
|
62 | - */ |
|
63 | - private $_ip_address = ''; |
|
64 | - |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * class constructor |
|
69 | - * |
|
70 | - * @access public |
|
71 | - * @param array $get |
|
72 | - * @param array $post |
|
73 | - * @param array $cookie |
|
74 | - */ |
|
75 | - public function __construct($get, $post, $cookie) |
|
76 | - { |
|
77 | - // grab request vars |
|
78 | - $this->_get = (array)$get; |
|
79 | - $this->_post = (array)$post; |
|
80 | - $this->_cookie = (array)$cookie; |
|
81 | - $this->_params = array_merge($this->_get, $this->_post); |
|
82 | - // AJAX ??? |
|
83 | - $this->ajax = defined('DOING_AJAX') ? true : false; |
|
84 | - $this->front_ajax = $this->is_set('ee_front_ajax') && (int)$this->get('ee_front_ajax') === 1; |
|
85 | - // grab user IP |
|
86 | - $this->_ip_address = $this->_visitor_ip(); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - public function get_params() |
|
95 | - { |
|
96 | - return $this->_get; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - public function post_params() |
|
105 | - { |
|
106 | - return $this->_post; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @return array |
|
113 | - */ |
|
114 | - public function cookie_params() |
|
115 | - { |
|
116 | - return $this->_cookie; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * returns contents of $_REQUEST |
|
123 | - * |
|
124 | - * @return array |
|
125 | - */ |
|
126 | - public function params() |
|
127 | - { |
|
128 | - return $this->_params; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * setter |
|
135 | - * |
|
136 | - * @access public |
|
137 | - * @param $key |
|
138 | - * @param $value |
|
139 | - * @param bool $override_ee |
|
140 | - * @return void |
|
141 | - */ |
|
142 | - public function set($key, $value, $override_ee = false) |
|
143 | - { |
|
144 | - // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
145 | - if ( |
|
146 | - $key !== 'ee' |
|
147 | - || ($key === 'ee' && empty($this->_params['ee'])) |
|
148 | - || ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee) |
|
149 | - ) { |
|
150 | - $this->_params[$key] = $value; |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * getter |
|
158 | - * |
|
159 | - * @access public |
|
160 | - * @param $key |
|
161 | - * @param null $default |
|
162 | - * @return mixed |
|
163 | - */ |
|
164 | - public function get($key, $default = null) |
|
165 | - { |
|
166 | - return isset($this->_params[$key]) ? $this->_params[$key] : $default; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * check if param exists |
|
173 | - * |
|
174 | - * @access public |
|
175 | - * @param $key |
|
176 | - * @return boolean |
|
177 | - */ |
|
178 | - public function is_set($key) |
|
179 | - { |
|
180 | - return isset($this->_params[$key]) ? true : false; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * remove param |
|
187 | - * |
|
188 | - * @access public |
|
189 | - * @param $key |
|
190 | - * @param bool $unset_from_global_too |
|
191 | - */ |
|
192 | - public function un_set($key, $unset_from_global_too = false) |
|
193 | - { |
|
194 | - unset($this->_params[$key]); |
|
195 | - if ($unset_from_global_too) { |
|
196 | - unset($_REQUEST[$key]); |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @return string |
|
204 | - */ |
|
205 | - public function ip_address() |
|
206 | - { |
|
207 | - return $this->_ip_address; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * _visitor_ip |
|
214 | - * attempt to get IP address of current visitor from server |
|
215 | - * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
216 | - * |
|
217 | - * @access public |
|
218 | - * @return string |
|
219 | - */ |
|
220 | - private function _visitor_ip() |
|
221 | - { |
|
222 | - $visitor_ip = '0.0.0.0'; |
|
223 | - $server_keys = array( |
|
224 | - 'HTTP_CLIENT_IP', |
|
225 | - 'HTTP_X_FORWARDED_FOR', |
|
226 | - 'HTTP_X_FORWARDED', |
|
227 | - 'HTTP_X_CLUSTER_CLIENT_IP', |
|
228 | - 'HTTP_FORWARDED_FOR', |
|
229 | - 'HTTP_FORWARDED', |
|
230 | - 'REMOTE_ADDR', |
|
231 | - ); |
|
232 | - foreach ($server_keys as $key) { |
|
233 | - if (isset($_SERVER[$key])) { |
|
234 | - foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) { |
|
235 | - if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
236 | - $visitor_ip = $ip; |
|
237 | - } |
|
238 | - } |
|
239 | - } |
|
240 | - } |
|
241 | - return $visitor_ip; |
|
242 | - } |
|
18 | + /** |
|
19 | + * @access private |
|
20 | + * @var array $_get $_GET parameters |
|
21 | + */ |
|
22 | + private $_get = array(); |
|
23 | + |
|
24 | + /** |
|
25 | + * @access private |
|
26 | + * @var array $_post $_POST parameters |
|
27 | + */ |
|
28 | + private $_post = array(); |
|
29 | + |
|
30 | + /** |
|
31 | + * @access private |
|
32 | + * @var array $_cookie $_COOKIE parameters |
|
33 | + */ |
|
34 | + private $_cookie = array(); |
|
35 | + |
|
36 | + /** |
|
37 | + * @access private |
|
38 | + * @var array $_params $_REQUEST parameters |
|
39 | + */ |
|
40 | + private $_params = array(); |
|
41 | + |
|
42 | + /** |
|
43 | + * whether current request is via AJAX |
|
44 | + * |
|
45 | + * @var boolean |
|
46 | + * @access public |
|
47 | + */ |
|
48 | + public $ajax = false; |
|
49 | + |
|
50 | + /** |
|
51 | + * whether current request is via AJAX from the frontend of the site |
|
52 | + * |
|
53 | + * @var boolean |
|
54 | + * @access public |
|
55 | + */ |
|
56 | + public $front_ajax = false; |
|
57 | + |
|
58 | + /** |
|
59 | + * IP address for request |
|
60 | + * |
|
61 | + * @var string $_ip_address |
|
62 | + */ |
|
63 | + private $_ip_address = ''; |
|
64 | + |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * class constructor |
|
69 | + * |
|
70 | + * @access public |
|
71 | + * @param array $get |
|
72 | + * @param array $post |
|
73 | + * @param array $cookie |
|
74 | + */ |
|
75 | + public function __construct($get, $post, $cookie) |
|
76 | + { |
|
77 | + // grab request vars |
|
78 | + $this->_get = (array)$get; |
|
79 | + $this->_post = (array)$post; |
|
80 | + $this->_cookie = (array)$cookie; |
|
81 | + $this->_params = array_merge($this->_get, $this->_post); |
|
82 | + // AJAX ??? |
|
83 | + $this->ajax = defined('DOING_AJAX') ? true : false; |
|
84 | + $this->front_ajax = $this->is_set('ee_front_ajax') && (int)$this->get('ee_front_ajax') === 1; |
|
85 | + // grab user IP |
|
86 | + $this->_ip_address = $this->_visitor_ip(); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + public function get_params() |
|
95 | + { |
|
96 | + return $this->_get; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + public function post_params() |
|
105 | + { |
|
106 | + return $this->_post; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @return array |
|
113 | + */ |
|
114 | + public function cookie_params() |
|
115 | + { |
|
116 | + return $this->_cookie; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * returns contents of $_REQUEST |
|
123 | + * |
|
124 | + * @return array |
|
125 | + */ |
|
126 | + public function params() |
|
127 | + { |
|
128 | + return $this->_params; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * setter |
|
135 | + * |
|
136 | + * @access public |
|
137 | + * @param $key |
|
138 | + * @param $value |
|
139 | + * @param bool $override_ee |
|
140 | + * @return void |
|
141 | + */ |
|
142 | + public function set($key, $value, $override_ee = false) |
|
143 | + { |
|
144 | + // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
145 | + if ( |
|
146 | + $key !== 'ee' |
|
147 | + || ($key === 'ee' && empty($this->_params['ee'])) |
|
148 | + || ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee) |
|
149 | + ) { |
|
150 | + $this->_params[$key] = $value; |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * getter |
|
158 | + * |
|
159 | + * @access public |
|
160 | + * @param $key |
|
161 | + * @param null $default |
|
162 | + * @return mixed |
|
163 | + */ |
|
164 | + public function get($key, $default = null) |
|
165 | + { |
|
166 | + return isset($this->_params[$key]) ? $this->_params[$key] : $default; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * check if param exists |
|
173 | + * |
|
174 | + * @access public |
|
175 | + * @param $key |
|
176 | + * @return boolean |
|
177 | + */ |
|
178 | + public function is_set($key) |
|
179 | + { |
|
180 | + return isset($this->_params[$key]) ? true : false; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * remove param |
|
187 | + * |
|
188 | + * @access public |
|
189 | + * @param $key |
|
190 | + * @param bool $unset_from_global_too |
|
191 | + */ |
|
192 | + public function un_set($key, $unset_from_global_too = false) |
|
193 | + { |
|
194 | + unset($this->_params[$key]); |
|
195 | + if ($unset_from_global_too) { |
|
196 | + unset($_REQUEST[$key]); |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @return string |
|
204 | + */ |
|
205 | + public function ip_address() |
|
206 | + { |
|
207 | + return $this->_ip_address; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * _visitor_ip |
|
214 | + * attempt to get IP address of current visitor from server |
|
215 | + * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
216 | + * |
|
217 | + * @access public |
|
218 | + * @return string |
|
219 | + */ |
|
220 | + private function _visitor_ip() |
|
221 | + { |
|
222 | + $visitor_ip = '0.0.0.0'; |
|
223 | + $server_keys = array( |
|
224 | + 'HTTP_CLIENT_IP', |
|
225 | + 'HTTP_X_FORWARDED_FOR', |
|
226 | + 'HTTP_X_FORWARDED', |
|
227 | + 'HTTP_X_CLUSTER_CLIENT_IP', |
|
228 | + 'HTTP_FORWARDED_FOR', |
|
229 | + 'HTTP_FORWARDED', |
|
230 | + 'REMOTE_ADDR', |
|
231 | + ); |
|
232 | + foreach ($server_keys as $key) { |
|
233 | + if (isset($_SERVER[$key])) { |
|
234 | + foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) { |
|
235 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
236 | + $visitor_ip = $ip; |
|
237 | + } |
|
238 | + } |
|
239 | + } |
|
240 | + } |
|
241 | + return $visitor_ip; |
|
242 | + } |
|
243 | 243 | |
244 | 244 | |
245 | 245 |
@@ -75,13 +75,13 @@ |
||
75 | 75 | public function __construct($get, $post, $cookie) |
76 | 76 | { |
77 | 77 | // grab request vars |
78 | - $this->_get = (array)$get; |
|
79 | - $this->_post = (array)$post; |
|
80 | - $this->_cookie = (array)$cookie; |
|
78 | + $this->_get = (array) $get; |
|
79 | + $this->_post = (array) $post; |
|
80 | + $this->_cookie = (array) $cookie; |
|
81 | 81 | $this->_params = array_merge($this->_get, $this->_post); |
82 | 82 | // AJAX ??? |
83 | 83 | $this->ajax = defined('DOING_AJAX') ? true : false; |
84 | - $this->front_ajax = $this->is_set('ee_front_ajax') && (int)$this->get('ee_front_ajax') === 1; |
|
84 | + $this->front_ajax = $this->is_set('ee_front_ajax') && (int) $this->get('ee_front_ajax') === 1; |
|
85 | 85 | // grab user IP |
86 | 86 | $this->_ip_address = $this->_visitor_ip(); |
87 | 87 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $update_txn = true, |
88 | 88 | $cancel_url = '' |
89 | 89 | ) { |
90 | - if ((float)$amount < 0) { |
|
90 | + if ((float) $amount < 0) { |
|
91 | 91 | throw new EE_Error( |
92 | 92 | sprintf( |
93 | 93 | __( |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
109 | 109 | $payment = $payment_method->type_obj()->process_payment( |
110 | 110 | $transaction, |
111 | - min($amount, $transaction->remaining()),//make sure we don't overcharge |
|
111 | + min($amount, $transaction->remaining()), //make sure we don't overcharge |
|
112 | 112 | $billing_form, |
113 | 113 | $return_url, |
114 | 114 | add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | $separate_IPN_request = true |
196 | 196 | ) { |
197 | 197 | EE_Registry::instance()->load_model('Change_Log'); |
198 | - $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data); |
|
198 | + $_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data); |
|
199 | 199 | EE_Processor_Base::set_IPN($separate_IPN_request); |
200 | 200 | $obj_for_log = null; |
201 | 201 | if ($transaction instanceof EE_Transaction) { |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | EEM_Change_Log::instance()->log( |
235 | 235 | EEM_Change_Log::type_gateway, |
236 | 236 | array( |
237 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
237 | + 'message' => 'IPN Exception: '.$e->getMessage(), |
|
238 | 238 | 'current_url' => EEH_URL::current_url(), |
239 | 239 | 'payment' => $e->getPaymentProperties(), |
240 | 240 | 'IPN_data' => $e->getIpnData(), |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | EEM_Change_Log::instance()->log( |
272 | 272 | EEM_Change_Log::type_gateway, |
273 | 273 | array( |
274 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
274 | + 'message' => 'IPN Exception: '.$e->getMessage(), |
|
275 | 275 | 'current_url' => EEH_URL::current_url(), |
276 | 276 | 'payment' => $e->getPaymentProperties(), |
277 | 277 | 'IPN_data' => $e->getIpnData(), |
@@ -633,15 +633,15 @@ discard block |
||
633 | 633 | //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
634 | 634 | if ($registration->paid() > 0) { |
635 | 635 | // ensure $available_refund_amount is NOT negative |
636 | - $available_refund_amount = (float)abs($available_refund_amount); |
|
636 | + $available_refund_amount = (float) abs($available_refund_amount); |
|
637 | 637 | // don't allow refund amount to exceed the available payment amount, OR the amount paid |
638 | - $refund_amount = min($available_refund_amount, (float)$registration->paid()); |
|
638 | + $refund_amount = min($available_refund_amount, (float) $registration->paid()); |
|
639 | 639 | // update $available_payment_amount |
640 | 640 | $available_refund_amount -= $refund_amount; |
641 | 641 | //calculate and set new REG_paid |
642 | 642 | $registration->set_paid($registration->paid() - $refund_amount); |
643 | 643 | // convert payment amount back to a negative value for storage in the db |
644 | - $refund_amount = (float)abs($refund_amount) * -1; |
|
644 | + $refund_amount = (float) abs($refund_amount) * -1; |
|
645 | 645 | // now save it |
646 | 646 | $this->_apply_registration_payment($registration, $payment, $refund_amount); |
647 | 647 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | EE_Registry::instance()->load_class('Processor_Base'); |
5 | 5 | |
@@ -16,737 +16,737 @@ discard block |
||
16 | 16 | class EE_Payment_Processor extends EE_Processor_Base |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var EE_Payment_Processor $_instance |
|
21 | - * @access private |
|
22 | - */ |
|
23 | - private static $_instance; |
|
24 | - |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * @singleton method used to instantiate class object |
|
29 | - * @access public |
|
30 | - * @return EE_Payment_Processor instance |
|
31 | - */ |
|
32 | - public static function instance() |
|
33 | - { |
|
34 | - // check if class object is instantiated |
|
35 | - if ( ! self::$_instance instanceof EE_Payment_Processor) { |
|
36 | - self::$_instance = new self(); |
|
37 | - } |
|
38 | - return self::$_instance; |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - *private constructor to prevent direct creation |
|
45 | - * |
|
46 | - * @Constructor |
|
47 | - * @access private |
|
48 | - */ |
|
49 | - private function __construct() |
|
50 | - { |
|
51 | - do_action('AHEE__EE_Payment_Processor__construct'); |
|
52 | - add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
59 | - * appropriately. Saves the payment that is generated |
|
60 | - * |
|
61 | - * @param EE_Payment_Method $payment_method |
|
62 | - * @param EE_Transaction $transaction |
|
63 | - * @param float $amount if only part of the transaction is to be paid for, how much. |
|
64 | - * Leave null if payment is for the full amount owing |
|
65 | - * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
66 | - * Receive_form_submission() should have |
|
67 | - * already been called on the billing form |
|
68 | - * (ie, its inputs should have their normalized values set). |
|
69 | - * @param string $return_url string used mostly by offsite gateways to specify |
|
70 | - * where to go AFTER the offsite gateway |
|
71 | - * @param string $method like 'CART', indicates who the client who called this was |
|
72 | - * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
73 | - * @param boolean $update_txn whether or not to call |
|
74 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
75 | - * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
76 | - * @return \EE_Payment |
|
77 | - * @throws \EE_Error |
|
78 | - */ |
|
79 | - public function process_payment( |
|
80 | - EE_Payment_Method $payment_method, |
|
81 | - EE_Transaction $transaction, |
|
82 | - $amount = null, |
|
83 | - $billing_form = null, |
|
84 | - $return_url = null, |
|
85 | - $method = 'CART', |
|
86 | - $by_admin = false, |
|
87 | - $update_txn = true, |
|
88 | - $cancel_url = '' |
|
89 | - ) { |
|
90 | - if ((float)$amount < 0) { |
|
91 | - throw new EE_Error( |
|
92 | - sprintf( |
|
93 | - __( |
|
94 | - 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
95 | - 'event_espresso' |
|
96 | - ), |
|
97 | - $amount, |
|
98 | - $transaction->ID() |
|
99 | - ) |
|
100 | - ); |
|
101 | - } |
|
102 | - // verify payment method |
|
103 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
104 | - // verify transaction |
|
105 | - EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
106 | - $transaction->set_payment_method_ID($payment_method->ID()); |
|
107 | - // verify payment method type |
|
108 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
109 | - $payment = $payment_method->type_obj()->process_payment( |
|
110 | - $transaction, |
|
111 | - min($amount, $transaction->remaining()),//make sure we don't overcharge |
|
112 | - $billing_form, |
|
113 | - $return_url, |
|
114 | - add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
115 | - $method, |
|
116 | - $by_admin |
|
117 | - ); |
|
118 | - // check if payment method uses an off-site gateway |
|
119 | - if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
120 | - // don't process payments for off-site gateways yet because no payment has occurred yet |
|
121 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
122 | - } |
|
123 | - return $payment; |
|
124 | - } else { |
|
125 | - EE_Error::add_error( |
|
126 | - sprintf( |
|
127 | - __('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'), |
|
128 | - '<br/>', |
|
129 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
130 | - ), __FILE__, __FUNCTION__, __LINE__ |
|
131 | - ); |
|
132 | - return null; |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @param EE_Transaction|int $transaction |
|
140 | - * @param EE_Payment_Method $payment_method |
|
141 | - * @throws EE_Error |
|
142 | - * @return string |
|
143 | - */ |
|
144 | - public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
145 | - { |
|
146 | - /** @type \EE_Transaction $transaction */ |
|
147 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
148 | - $primary_reg = $transaction->primary_registration(); |
|
149 | - if ( ! $primary_reg instanceof EE_Registration) { |
|
150 | - throw new EE_Error( |
|
151 | - sprintf( |
|
152 | - __( |
|
153 | - "Cannot get IPN URL for transaction with ID %d because it has no primary registration", |
|
154 | - "event_espresso" |
|
155 | - ), |
|
156 | - $transaction->ID() |
|
157 | - ) |
|
158 | - ); |
|
159 | - } |
|
160 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
161 | - $url = add_query_arg( |
|
162 | - array( |
|
163 | - 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
164 | - 'ee_payment_method' => $payment_method->slug(), |
|
165 | - ), |
|
166 | - EE_Registry::instance()->CFG->core->txn_page_url() |
|
167 | - ); |
|
168 | - return $url; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
175 | - * we can easily find what registration the IPN is for and what payment method. |
|
176 | - * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
177 | - * If a payment is found for the IPN info, it is saved. |
|
178 | - * |
|
179 | - * @param array $_req_data eg $_REQUEST |
|
180 | - * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
181 | - * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
182 | - * @param boolean $update_txn whether or not to call |
|
183 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
184 | - * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) |
|
185 | - * or is processed manually ( false like Mijireh ) |
|
186 | - * @throws EE_Error |
|
187 | - * @throws Exception |
|
188 | - * @return EE_Payment |
|
189 | - */ |
|
190 | - public function process_ipn( |
|
191 | - $_req_data, |
|
192 | - $transaction = null, |
|
193 | - $payment_method = null, |
|
194 | - $update_txn = true, |
|
195 | - $separate_IPN_request = true |
|
196 | - ) { |
|
197 | - EE_Registry::instance()->load_model('Change_Log'); |
|
198 | - $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data); |
|
199 | - EE_Processor_Base::set_IPN($separate_IPN_request); |
|
200 | - $obj_for_log = null; |
|
201 | - if ($transaction instanceof EE_Transaction) { |
|
202 | - $obj_for_log = $transaction; |
|
203 | - if ($payment_method instanceof EE_Payment_Method) { |
|
204 | - $obj_for_log = EEM_Payment::instance()->get_one( |
|
205 | - array( |
|
206 | - array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
207 | - 'order_by' => array('PAY_timestamp' => 'desc'), |
|
208 | - ) |
|
209 | - ); |
|
210 | - } |
|
211 | - } else if ($payment_method instanceof EE_Payment) { |
|
212 | - $obj_for_log = $payment_method; |
|
213 | - } |
|
214 | - $log = EEM_Change_Log::instance()->log( |
|
215 | - EEM_Change_Log::type_gateway, |
|
216 | - array('IPN data received' => $_req_data), |
|
217 | - $obj_for_log |
|
218 | - ); |
|
219 | - try { |
|
220 | - /** |
|
221 | - * @var EE_Payment $payment |
|
222 | - */ |
|
223 | - $payment = null; |
|
224 | - if ($transaction && $payment_method) { |
|
225 | - /** @type EE_Transaction $transaction */ |
|
226 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
227 | - /** @type EE_Payment_Method $payment_method */ |
|
228 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
229 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
230 | - try { |
|
231 | - $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
232 | - $log->set_object($payment); |
|
233 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
234 | - EEM_Change_Log::instance()->log( |
|
235 | - EEM_Change_Log::type_gateway, |
|
236 | - array( |
|
237 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
238 | - 'current_url' => EEH_URL::current_url(), |
|
239 | - 'payment' => $e->getPaymentProperties(), |
|
240 | - 'IPN_data' => $e->getIpnData(), |
|
241 | - ), |
|
242 | - $obj_for_log |
|
243 | - ); |
|
244 | - return $e->getPayment(); |
|
245 | - } |
|
246 | - } else { |
|
247 | - // not a payment |
|
248 | - EE_Error::add_error( |
|
249 | - sprintf( |
|
250 | - __('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'), |
|
251 | - '<br/>', |
|
252 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
253 | - ), |
|
254 | - __FILE__, __FUNCTION__, __LINE__ |
|
255 | - ); |
|
256 | - } |
|
257 | - } else { |
|
258 | - //that's actually pretty ok. The IPN just wasn't able |
|
259 | - //to identify which transaction or payment method this was for |
|
260 | - // give all active payment methods a chance to claim it |
|
261 | - $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
262 | - foreach ($active_payment_methods as $active_payment_method) { |
|
263 | - try { |
|
264 | - $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
265 | - $payment_method = $active_payment_method; |
|
266 | - EEM_Change_Log::instance()->log( |
|
267 | - EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment |
|
268 | - ); |
|
269 | - break; |
|
270 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
271 | - EEM_Change_Log::instance()->log( |
|
272 | - EEM_Change_Log::type_gateway, |
|
273 | - array( |
|
274 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
275 | - 'current_url' => EEH_URL::current_url(), |
|
276 | - 'payment' => $e->getPaymentProperties(), |
|
277 | - 'IPN_data' => $e->getIpnData(), |
|
278 | - ), |
|
279 | - $obj_for_log |
|
280 | - ); |
|
281 | - return $e->getPayment(); |
|
282 | - } catch (EE_Error $e) { |
|
283 | - //that's fine- it apparently couldn't handle the IPN |
|
284 | - } |
|
285 | - } |
|
286 | - } |
|
287 | - // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
288 | - if ($payment instanceof EE_Payment) { |
|
289 | - $payment->save(); |
|
290 | - // update the TXN |
|
291 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request); |
|
292 | - } else { |
|
293 | - //we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
294 | - if ($payment_method) { |
|
295 | - EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method); |
|
296 | - } elseif ($transaction) { |
|
297 | - EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction); |
|
298 | - } |
|
299 | - } |
|
300 | - return $payment; |
|
301 | - } catch (EE_Error $e) { |
|
302 | - do_action( |
|
303 | - 'AHEE__log', __FILE__, __FUNCTION__, sprintf( |
|
304 | - __('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'), |
|
305 | - print_r($transaction, true), |
|
306 | - print_r($_req_data, true), |
|
307 | - $e->getMessage() |
|
308 | - ) |
|
309 | - ); |
|
310 | - throw $e; |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * Removes any non-printable illegal characters from the input, |
|
318 | - * which might cause a raucous when trying to insert into the database |
|
319 | - * |
|
320 | - * @param array $request_data |
|
321 | - * @return array |
|
322 | - */ |
|
323 | - protected function _remove_unusable_characters_from_array(array $request_data) |
|
324 | - { |
|
325 | - $return_data = array(); |
|
326 | - foreach ($request_data as $key => $value) { |
|
327 | - $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value); |
|
328 | - } |
|
329 | - return $return_data; |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * Removes any non-printable illegal characters from the input, |
|
336 | - * which might cause a raucous when trying to insert into the database |
|
337 | - * |
|
338 | - * @param string $request_data |
|
339 | - * @return string |
|
340 | - */ |
|
341 | - protected function _remove_unusable_characters($request_data) |
|
342 | - { |
|
343 | - return preg_replace('/[^[:print:]]/', '', $request_data); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * Should be called just before displaying the payment attempt results to the user, |
|
350 | - * when the payment attempt has finished. Some payment methods may have special |
|
351 | - * logic to perform here. For example, if process_payment() happens on a special request |
|
352 | - * and then the user is redirected to a page that displays the payment's status, this |
|
353 | - * should be called while loading the page that displays the payment's status. If the user is |
|
354 | - * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
355 | - * provider. |
|
356 | - * |
|
357 | - * @param EE_Transaction|int $transaction |
|
358 | - * @param bool $update_txn whether or not to call |
|
359 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
360 | - * @throws \EE_Error |
|
361 | - * @return EE_Payment |
|
362 | - * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
363 | - * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
364 | - */ |
|
365 | - public function finalize_payment_for($transaction, $update_txn = true) |
|
366 | - { |
|
367 | - /** @var $transaction EE_Transaction */ |
|
368 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
369 | - $last_payment_method = $transaction->payment_method(); |
|
370 | - if ($last_payment_method instanceof EE_Payment_Method) { |
|
371 | - $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
372 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
373 | - return $payment; |
|
374 | - } else { |
|
375 | - return null; |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
383 | - * |
|
384 | - * @param EE_Payment_Method $payment_method |
|
385 | - * @param EE_Payment $payment_to_refund |
|
386 | - * @param array $refund_info |
|
387 | - * @return EE_Payment |
|
388 | - * @throws \EE_Error |
|
389 | - */ |
|
390 | - public function process_refund( |
|
391 | - EE_Payment_Method $payment_method, |
|
392 | - EE_Payment $payment_to_refund, |
|
393 | - $refund_info = array() |
|
394 | - ) { |
|
395 | - if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
396 | - $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
397 | - $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
398 | - } |
|
399 | - return $payment_to_refund; |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * This should be called each time there may have been an update to a |
|
406 | - * payment on a transaction (ie, we asked for a payment to process a |
|
407 | - * payment for a transaction, or we told a payment method about an IPN, or |
|
408 | - * we told a payment method to |
|
409 | - * "finalize_payment_for" (a transaction), or we told a payment method to |
|
410 | - * process a refund. This should handle firing the correct hooks to |
|
411 | - * indicate |
|
412 | - * what exactly happened and updating the transaction appropriately). This |
|
413 | - * could be integrated directly into EE_Transaction upon save, but we want |
|
414 | - * this logic to be separate from 'normal' plain-jane saving and updating |
|
415 | - * of transactions and payments, and to be tied to payment processing. |
|
416 | - * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
417 | - * of previous code to decide whether or not to save (because the payment passed into |
|
418 | - * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
419 | - * in which case we only want that payment object for some temporary usage during this request, |
|
420 | - * but we don't want it to be saved). |
|
421 | - * |
|
422 | - * @param EE_Transaction|int $transaction |
|
423 | - * @param EE_Payment $payment |
|
424 | - * @param boolean $update_txn |
|
425 | - * whether or not to call |
|
426 | - * EE_Transaction_Processor:: |
|
427 | - * update_transaction_and_registrations_after_checkout_or_payment() |
|
428 | - * (you can save 1 DB query if you know you're going |
|
429 | - * to save it later instead) |
|
430 | - * @param bool $IPN |
|
431 | - * if processing IPNs or other similar payment |
|
432 | - * related activities that occur in alternate |
|
433 | - * requests than the main one that is processing the |
|
434 | - * TXN, then set this to true to check whether the |
|
435 | - * TXN is locked before updating |
|
436 | - * @throws \EE_Error |
|
437 | - */ |
|
438 | - public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
439 | - { |
|
440 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
441 | - /** @type EE_Transaction $transaction */ |
|
442 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
443 | - // can we freely update the TXN at this moment? |
|
444 | - if ($IPN && $transaction->is_locked()) { |
|
445 | - // don't update the transaction at this exact moment |
|
446 | - // because the TXN is active in another request |
|
447 | - EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
448 | - time(), |
|
449 | - $transaction->ID(), |
|
450 | - $payment->ID() |
|
451 | - ); |
|
452 | - } else { |
|
453 | - // verify payment and that it has been saved |
|
454 | - if ($payment instanceof EE_Payment && $payment->ID()) { |
|
455 | - if ( |
|
456 | - $payment->payment_method() instanceof EE_Payment_Method |
|
457 | - && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
458 | - ) { |
|
459 | - $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
460 | - // update TXN registrations with payment info |
|
461 | - $this->process_registration_payments($transaction, $payment); |
|
462 | - } |
|
463 | - $do_action = $payment->just_approved() |
|
464 | - ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
465 | - : $do_action; |
|
466 | - } else { |
|
467 | - // send out notifications |
|
468 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
469 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
470 | - } |
|
471 | - if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
472 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
473 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
474 | - // set new value for total paid |
|
475 | - $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
476 | - // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
477 | - if ($update_txn) { |
|
478 | - $this->_post_payment_processing($transaction, $payment, $IPN); |
|
479 | - } |
|
480 | - } |
|
481 | - // granular hook for others to use. |
|
482 | - do_action($do_action, $transaction, $payment); |
|
483 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
484 | - //global hook for others to use. |
|
485 | - do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
486 | - } |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * update registrations REG_paid field after successful payment and link registrations with payment |
|
493 | - * |
|
494 | - * @param EE_Transaction $transaction |
|
495 | - * @param EE_Payment $payment |
|
496 | - * @param EE_Registration[] $registrations |
|
497 | - * @throws \EE_Error |
|
498 | - */ |
|
499 | - public function process_registration_payments( |
|
500 | - EE_Transaction $transaction, |
|
501 | - EE_Payment $payment, |
|
502 | - $registrations = array() |
|
503 | - ) { |
|
504 | - // only process if payment was successful |
|
505 | - if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
506 | - return; |
|
507 | - } |
|
508 | - //EEM_Registration::instance()->show_next_x_db_queries(); |
|
509 | - if (empty($registrations)) { |
|
510 | - // find registrations with monies owing that can receive a payment |
|
511 | - $registrations = $transaction->registrations( |
|
512 | - array( |
|
513 | - array( |
|
514 | - // only these reg statuses can receive payments |
|
515 | - 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
516 | - 'REG_final_price' => array('!=', 0), |
|
517 | - 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
518 | - ), |
|
519 | - ) |
|
520 | - ); |
|
521 | - } |
|
522 | - // still nothing ??!?? |
|
523 | - if (empty($registrations)) { |
|
524 | - return; |
|
525 | - } |
|
526 | - // todo: break out the following logic into a separate strategy class |
|
527 | - // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
528 | - // todo: which would apply payments using the capitalist "first come first paid" approach |
|
529 | - // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
530 | - // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
531 | - // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
532 | - $refund = $payment->is_a_refund(); |
|
533 | - // how much is available to apply to registrations? |
|
534 | - $available_payment_amount = abs($payment->amount()); |
|
535 | - foreach ($registrations as $registration) { |
|
536 | - if ($registration instanceof EE_Registration) { |
|
537 | - // nothing left? |
|
538 | - if ($available_payment_amount <= 0) { |
|
539 | - break; |
|
540 | - } |
|
541 | - if ($refund) { |
|
542 | - $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount); |
|
543 | - } else { |
|
544 | - $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount); |
|
545 | - } |
|
546 | - } |
|
547 | - } |
|
548 | - if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) { |
|
549 | - EE_Error::add_attention( |
|
550 | - sprintf( |
|
551 | - __('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', |
|
552 | - 'event_espresso'), |
|
553 | - EEH_Template::format_currency($available_payment_amount), |
|
554 | - implode(', ', array_keys($registrations)), |
|
555 | - '<br/>', |
|
556 | - EEH_Template::format_currency($payment->amount()) |
|
557 | - ), |
|
558 | - __FILE__, __FUNCTION__, __LINE__ |
|
559 | - ); |
|
560 | - } |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * update registration REG_paid field after successful payment and link registration with payment |
|
567 | - * |
|
568 | - * @param EE_Registration $registration |
|
569 | - * @param EE_Payment $payment |
|
570 | - * @param float $available_payment_amount |
|
571 | - * @return float |
|
572 | - * @throws \EE_Error |
|
573 | - */ |
|
574 | - public function process_registration_payment( |
|
575 | - EE_Registration $registration, |
|
576 | - EE_Payment $payment, |
|
577 | - $available_payment_amount = 0.00 |
|
578 | - ) { |
|
579 | - $owing = $registration->final_price() - $registration->paid(); |
|
580 | - if ($owing > 0) { |
|
581 | - // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
582 | - $payment_amount = min($available_payment_amount, $owing); |
|
583 | - // update $available_payment_amount |
|
584 | - $available_payment_amount -= $payment_amount; |
|
585 | - //calculate and set new REG_paid |
|
586 | - $registration->set_paid($registration->paid() + $payment_amount); |
|
587 | - // now save it |
|
588 | - $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
589 | - } |
|
590 | - return $available_payment_amount; |
|
591 | - } |
|
592 | - |
|
593 | - |
|
594 | - |
|
595 | - /** |
|
596 | - * update registration REG_paid field after successful payment and link registration with payment |
|
597 | - * |
|
598 | - * @param EE_Registration $registration |
|
599 | - * @param EE_Payment $payment |
|
600 | - * @param float $payment_amount |
|
601 | - * @return void |
|
602 | - * @throws \EE_Error |
|
603 | - */ |
|
604 | - protected function _apply_registration_payment( |
|
605 | - EE_Registration $registration, |
|
606 | - EE_Payment $payment, |
|
607 | - $payment_amount = 0.00 |
|
608 | - ) { |
|
609 | - // find any existing reg payment records for this registration and payment |
|
610 | - $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
611 | - array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
612 | - ); |
|
613 | - // if existing registration payment exists |
|
614 | - if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
615 | - // then update that record |
|
616 | - $existing_reg_payment->set_amount($payment_amount); |
|
617 | - $existing_reg_payment->save(); |
|
618 | - } else { |
|
619 | - // or add new relation between registration and payment and set amount |
|
620 | - $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount)); |
|
621 | - // make it stick |
|
622 | - $registration->save(); |
|
623 | - } |
|
624 | - } |
|
625 | - |
|
626 | - |
|
627 | - |
|
628 | - /** |
|
629 | - * update registration REG_paid field after refund and link registration with payment |
|
630 | - * |
|
631 | - * @param EE_Registration $registration |
|
632 | - * @param EE_Payment $payment |
|
633 | - * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
634 | - * @return float |
|
635 | - * @throws \EE_Error |
|
636 | - */ |
|
637 | - public function process_registration_refund( |
|
638 | - EE_Registration $registration, |
|
639 | - EE_Payment $payment, |
|
640 | - $available_refund_amount = 0.00 |
|
641 | - ) { |
|
642 | - //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
643 | - if ($registration->paid() > 0) { |
|
644 | - // ensure $available_refund_amount is NOT negative |
|
645 | - $available_refund_amount = (float)abs($available_refund_amount); |
|
646 | - // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
647 | - $refund_amount = min($available_refund_amount, (float)$registration->paid()); |
|
648 | - // update $available_payment_amount |
|
649 | - $available_refund_amount -= $refund_amount; |
|
650 | - //calculate and set new REG_paid |
|
651 | - $registration->set_paid($registration->paid() - $refund_amount); |
|
652 | - // convert payment amount back to a negative value for storage in the db |
|
653 | - $refund_amount = (float)abs($refund_amount) * -1; |
|
654 | - // now save it |
|
655 | - $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
656 | - } |
|
657 | - return $available_refund_amount; |
|
658 | - } |
|
659 | - |
|
660 | - |
|
661 | - |
|
662 | - /** |
|
663 | - * Process payments and transaction after payment process completed. |
|
664 | - * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
665 | - * if this request happens to be processing an IPN, |
|
666 | - * then we will also set the Payment Options Reg Step to completed, |
|
667 | - * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
668 | - * |
|
669 | - * @param EE_Transaction $transaction |
|
670 | - * @param EE_Payment $payment |
|
671 | - * @param bool $IPN |
|
672 | - * @throws \EE_Error |
|
673 | - */ |
|
674 | - protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
675 | - { |
|
676 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
677 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
678 | - // is the Payment Options Reg Step completed ? |
|
679 | - $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
680 | - // if the Payment Options Reg Step is completed... |
|
681 | - $revisit = $payment_options_step_completed === true ? true : false; |
|
682 | - // then this is kinda sorta a revisit with regards to payments at least |
|
683 | - $transaction_processor->set_revisit($revisit); |
|
684 | - // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
685 | - if ( |
|
686 | - $IPN |
|
687 | - && $payment_options_step_completed !== true |
|
688 | - && ($payment->is_approved() || $payment->is_pending()) |
|
689 | - ) { |
|
690 | - $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
691 | - 'payment_options' |
|
692 | - ); |
|
693 | - } |
|
694 | - // maybe update status, but don't save transaction just yet |
|
695 | - $transaction->update_status_based_on_total_paid(false); |
|
696 | - // check if 'finalize_registration' step has been completed... |
|
697 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
698 | - // if this is an IPN and the final step has not been initiated |
|
699 | - if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
700 | - // and if it hasn't already been set as being started... |
|
701 | - $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
702 | - } |
|
703 | - $transaction->save(); |
|
704 | - // because the above will return false if the final step was not fully completed, we need to check again... |
|
705 | - if ($IPN && $finalized !== false) { |
|
706 | - // and if we are all good to go, then send out notifications |
|
707 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
708 | - //ok, now process the transaction according to the payment |
|
709 | - $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment); |
|
710 | - } |
|
711 | - // DEBUG LOG |
|
712 | - $payment_method = $payment->payment_method(); |
|
713 | - if ($payment_method instanceof EE_Payment_Method) { |
|
714 | - $payment_method_type_obj = $payment_method->type_obj(); |
|
715 | - if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
716 | - $gateway = $payment_method_type_obj->get_gateway(); |
|
717 | - if ($gateway instanceof EE_Gateway) { |
|
718 | - $gateway->log( |
|
719 | - array( |
|
720 | - 'message' => __('Post Payment Transaction Details', 'event_espresso'), |
|
721 | - 'transaction' => $transaction->model_field_array(), |
|
722 | - 'finalized' => $finalized, |
|
723 | - 'IPN' => $IPN, |
|
724 | - 'deliver_notifications' => has_filter( |
|
725 | - 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
726 | - ), |
|
727 | - ), |
|
728 | - $payment |
|
729 | - ); |
|
730 | - } |
|
731 | - } |
|
732 | - } |
|
733 | - } |
|
734 | - |
|
735 | - |
|
736 | - |
|
737 | - /** |
|
738 | - * Force posts to PayPal to use TLS v1.2. See: |
|
739 | - * https://core.trac.wordpress.org/ticket/36320 |
|
740 | - * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
741 | - * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
742 | - * This will affect paypal standard, pro, express, and payflow. |
|
743 | - */ |
|
744 | - public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
745 | - { |
|
746 | - if (strstr($url, 'https://') && strstr($url, '.paypal.com')) { |
|
747 | - //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
748 | - //instead of the constant because it might not be defined |
|
749 | - curl_setopt($handle, CURLOPT_SSLVERSION, 1); |
|
750 | - } |
|
751 | - } |
|
19 | + /** |
|
20 | + * @var EE_Payment_Processor $_instance |
|
21 | + * @access private |
|
22 | + */ |
|
23 | + private static $_instance; |
|
24 | + |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * @singleton method used to instantiate class object |
|
29 | + * @access public |
|
30 | + * @return EE_Payment_Processor instance |
|
31 | + */ |
|
32 | + public static function instance() |
|
33 | + { |
|
34 | + // check if class object is instantiated |
|
35 | + if ( ! self::$_instance instanceof EE_Payment_Processor) { |
|
36 | + self::$_instance = new self(); |
|
37 | + } |
|
38 | + return self::$_instance; |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + *private constructor to prevent direct creation |
|
45 | + * |
|
46 | + * @Constructor |
|
47 | + * @access private |
|
48 | + */ |
|
49 | + private function __construct() |
|
50 | + { |
|
51 | + do_action('AHEE__EE_Payment_Processor__construct'); |
|
52 | + add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
59 | + * appropriately. Saves the payment that is generated |
|
60 | + * |
|
61 | + * @param EE_Payment_Method $payment_method |
|
62 | + * @param EE_Transaction $transaction |
|
63 | + * @param float $amount if only part of the transaction is to be paid for, how much. |
|
64 | + * Leave null if payment is for the full amount owing |
|
65 | + * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
66 | + * Receive_form_submission() should have |
|
67 | + * already been called on the billing form |
|
68 | + * (ie, its inputs should have their normalized values set). |
|
69 | + * @param string $return_url string used mostly by offsite gateways to specify |
|
70 | + * where to go AFTER the offsite gateway |
|
71 | + * @param string $method like 'CART', indicates who the client who called this was |
|
72 | + * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
73 | + * @param boolean $update_txn whether or not to call |
|
74 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
75 | + * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
76 | + * @return \EE_Payment |
|
77 | + * @throws \EE_Error |
|
78 | + */ |
|
79 | + public function process_payment( |
|
80 | + EE_Payment_Method $payment_method, |
|
81 | + EE_Transaction $transaction, |
|
82 | + $amount = null, |
|
83 | + $billing_form = null, |
|
84 | + $return_url = null, |
|
85 | + $method = 'CART', |
|
86 | + $by_admin = false, |
|
87 | + $update_txn = true, |
|
88 | + $cancel_url = '' |
|
89 | + ) { |
|
90 | + if ((float)$amount < 0) { |
|
91 | + throw new EE_Error( |
|
92 | + sprintf( |
|
93 | + __( |
|
94 | + 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
95 | + 'event_espresso' |
|
96 | + ), |
|
97 | + $amount, |
|
98 | + $transaction->ID() |
|
99 | + ) |
|
100 | + ); |
|
101 | + } |
|
102 | + // verify payment method |
|
103 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
104 | + // verify transaction |
|
105 | + EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
106 | + $transaction->set_payment_method_ID($payment_method->ID()); |
|
107 | + // verify payment method type |
|
108 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
109 | + $payment = $payment_method->type_obj()->process_payment( |
|
110 | + $transaction, |
|
111 | + min($amount, $transaction->remaining()),//make sure we don't overcharge |
|
112 | + $billing_form, |
|
113 | + $return_url, |
|
114 | + add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
115 | + $method, |
|
116 | + $by_admin |
|
117 | + ); |
|
118 | + // check if payment method uses an off-site gateway |
|
119 | + if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
120 | + // don't process payments for off-site gateways yet because no payment has occurred yet |
|
121 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
122 | + } |
|
123 | + return $payment; |
|
124 | + } else { |
|
125 | + EE_Error::add_error( |
|
126 | + sprintf( |
|
127 | + __('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'), |
|
128 | + '<br/>', |
|
129 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
130 | + ), __FILE__, __FUNCTION__, __LINE__ |
|
131 | + ); |
|
132 | + return null; |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @param EE_Transaction|int $transaction |
|
140 | + * @param EE_Payment_Method $payment_method |
|
141 | + * @throws EE_Error |
|
142 | + * @return string |
|
143 | + */ |
|
144 | + public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
145 | + { |
|
146 | + /** @type \EE_Transaction $transaction */ |
|
147 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
148 | + $primary_reg = $transaction->primary_registration(); |
|
149 | + if ( ! $primary_reg instanceof EE_Registration) { |
|
150 | + throw new EE_Error( |
|
151 | + sprintf( |
|
152 | + __( |
|
153 | + "Cannot get IPN URL for transaction with ID %d because it has no primary registration", |
|
154 | + "event_espresso" |
|
155 | + ), |
|
156 | + $transaction->ID() |
|
157 | + ) |
|
158 | + ); |
|
159 | + } |
|
160 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
161 | + $url = add_query_arg( |
|
162 | + array( |
|
163 | + 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
164 | + 'ee_payment_method' => $payment_method->slug(), |
|
165 | + ), |
|
166 | + EE_Registry::instance()->CFG->core->txn_page_url() |
|
167 | + ); |
|
168 | + return $url; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
175 | + * we can easily find what registration the IPN is for and what payment method. |
|
176 | + * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
177 | + * If a payment is found for the IPN info, it is saved. |
|
178 | + * |
|
179 | + * @param array $_req_data eg $_REQUEST |
|
180 | + * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
181 | + * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
182 | + * @param boolean $update_txn whether or not to call |
|
183 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
184 | + * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) |
|
185 | + * or is processed manually ( false like Mijireh ) |
|
186 | + * @throws EE_Error |
|
187 | + * @throws Exception |
|
188 | + * @return EE_Payment |
|
189 | + */ |
|
190 | + public function process_ipn( |
|
191 | + $_req_data, |
|
192 | + $transaction = null, |
|
193 | + $payment_method = null, |
|
194 | + $update_txn = true, |
|
195 | + $separate_IPN_request = true |
|
196 | + ) { |
|
197 | + EE_Registry::instance()->load_model('Change_Log'); |
|
198 | + $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data); |
|
199 | + EE_Processor_Base::set_IPN($separate_IPN_request); |
|
200 | + $obj_for_log = null; |
|
201 | + if ($transaction instanceof EE_Transaction) { |
|
202 | + $obj_for_log = $transaction; |
|
203 | + if ($payment_method instanceof EE_Payment_Method) { |
|
204 | + $obj_for_log = EEM_Payment::instance()->get_one( |
|
205 | + array( |
|
206 | + array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
207 | + 'order_by' => array('PAY_timestamp' => 'desc'), |
|
208 | + ) |
|
209 | + ); |
|
210 | + } |
|
211 | + } else if ($payment_method instanceof EE_Payment) { |
|
212 | + $obj_for_log = $payment_method; |
|
213 | + } |
|
214 | + $log = EEM_Change_Log::instance()->log( |
|
215 | + EEM_Change_Log::type_gateway, |
|
216 | + array('IPN data received' => $_req_data), |
|
217 | + $obj_for_log |
|
218 | + ); |
|
219 | + try { |
|
220 | + /** |
|
221 | + * @var EE_Payment $payment |
|
222 | + */ |
|
223 | + $payment = null; |
|
224 | + if ($transaction && $payment_method) { |
|
225 | + /** @type EE_Transaction $transaction */ |
|
226 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
227 | + /** @type EE_Payment_Method $payment_method */ |
|
228 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
229 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
230 | + try { |
|
231 | + $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
232 | + $log->set_object($payment); |
|
233 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
234 | + EEM_Change_Log::instance()->log( |
|
235 | + EEM_Change_Log::type_gateway, |
|
236 | + array( |
|
237 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
238 | + 'current_url' => EEH_URL::current_url(), |
|
239 | + 'payment' => $e->getPaymentProperties(), |
|
240 | + 'IPN_data' => $e->getIpnData(), |
|
241 | + ), |
|
242 | + $obj_for_log |
|
243 | + ); |
|
244 | + return $e->getPayment(); |
|
245 | + } |
|
246 | + } else { |
|
247 | + // not a payment |
|
248 | + EE_Error::add_error( |
|
249 | + sprintf( |
|
250 | + __('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'), |
|
251 | + '<br/>', |
|
252 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
253 | + ), |
|
254 | + __FILE__, __FUNCTION__, __LINE__ |
|
255 | + ); |
|
256 | + } |
|
257 | + } else { |
|
258 | + //that's actually pretty ok. The IPN just wasn't able |
|
259 | + //to identify which transaction or payment method this was for |
|
260 | + // give all active payment methods a chance to claim it |
|
261 | + $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
262 | + foreach ($active_payment_methods as $active_payment_method) { |
|
263 | + try { |
|
264 | + $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
265 | + $payment_method = $active_payment_method; |
|
266 | + EEM_Change_Log::instance()->log( |
|
267 | + EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment |
|
268 | + ); |
|
269 | + break; |
|
270 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
271 | + EEM_Change_Log::instance()->log( |
|
272 | + EEM_Change_Log::type_gateway, |
|
273 | + array( |
|
274 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
275 | + 'current_url' => EEH_URL::current_url(), |
|
276 | + 'payment' => $e->getPaymentProperties(), |
|
277 | + 'IPN_data' => $e->getIpnData(), |
|
278 | + ), |
|
279 | + $obj_for_log |
|
280 | + ); |
|
281 | + return $e->getPayment(); |
|
282 | + } catch (EE_Error $e) { |
|
283 | + //that's fine- it apparently couldn't handle the IPN |
|
284 | + } |
|
285 | + } |
|
286 | + } |
|
287 | + // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
288 | + if ($payment instanceof EE_Payment) { |
|
289 | + $payment->save(); |
|
290 | + // update the TXN |
|
291 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request); |
|
292 | + } else { |
|
293 | + //we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
294 | + if ($payment_method) { |
|
295 | + EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method); |
|
296 | + } elseif ($transaction) { |
|
297 | + EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction); |
|
298 | + } |
|
299 | + } |
|
300 | + return $payment; |
|
301 | + } catch (EE_Error $e) { |
|
302 | + do_action( |
|
303 | + 'AHEE__log', __FILE__, __FUNCTION__, sprintf( |
|
304 | + __('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'), |
|
305 | + print_r($transaction, true), |
|
306 | + print_r($_req_data, true), |
|
307 | + $e->getMessage() |
|
308 | + ) |
|
309 | + ); |
|
310 | + throw $e; |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * Removes any non-printable illegal characters from the input, |
|
318 | + * which might cause a raucous when trying to insert into the database |
|
319 | + * |
|
320 | + * @param array $request_data |
|
321 | + * @return array |
|
322 | + */ |
|
323 | + protected function _remove_unusable_characters_from_array(array $request_data) |
|
324 | + { |
|
325 | + $return_data = array(); |
|
326 | + foreach ($request_data as $key => $value) { |
|
327 | + $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value); |
|
328 | + } |
|
329 | + return $return_data; |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * Removes any non-printable illegal characters from the input, |
|
336 | + * which might cause a raucous when trying to insert into the database |
|
337 | + * |
|
338 | + * @param string $request_data |
|
339 | + * @return string |
|
340 | + */ |
|
341 | + protected function _remove_unusable_characters($request_data) |
|
342 | + { |
|
343 | + return preg_replace('/[^[:print:]]/', '', $request_data); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * Should be called just before displaying the payment attempt results to the user, |
|
350 | + * when the payment attempt has finished. Some payment methods may have special |
|
351 | + * logic to perform here. For example, if process_payment() happens on a special request |
|
352 | + * and then the user is redirected to a page that displays the payment's status, this |
|
353 | + * should be called while loading the page that displays the payment's status. If the user is |
|
354 | + * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
355 | + * provider. |
|
356 | + * |
|
357 | + * @param EE_Transaction|int $transaction |
|
358 | + * @param bool $update_txn whether or not to call |
|
359 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
360 | + * @throws \EE_Error |
|
361 | + * @return EE_Payment |
|
362 | + * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
363 | + * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
364 | + */ |
|
365 | + public function finalize_payment_for($transaction, $update_txn = true) |
|
366 | + { |
|
367 | + /** @var $transaction EE_Transaction */ |
|
368 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
369 | + $last_payment_method = $transaction->payment_method(); |
|
370 | + if ($last_payment_method instanceof EE_Payment_Method) { |
|
371 | + $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
372 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
373 | + return $payment; |
|
374 | + } else { |
|
375 | + return null; |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
383 | + * |
|
384 | + * @param EE_Payment_Method $payment_method |
|
385 | + * @param EE_Payment $payment_to_refund |
|
386 | + * @param array $refund_info |
|
387 | + * @return EE_Payment |
|
388 | + * @throws \EE_Error |
|
389 | + */ |
|
390 | + public function process_refund( |
|
391 | + EE_Payment_Method $payment_method, |
|
392 | + EE_Payment $payment_to_refund, |
|
393 | + $refund_info = array() |
|
394 | + ) { |
|
395 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
396 | + $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
397 | + $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
398 | + } |
|
399 | + return $payment_to_refund; |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * This should be called each time there may have been an update to a |
|
406 | + * payment on a transaction (ie, we asked for a payment to process a |
|
407 | + * payment for a transaction, or we told a payment method about an IPN, or |
|
408 | + * we told a payment method to |
|
409 | + * "finalize_payment_for" (a transaction), or we told a payment method to |
|
410 | + * process a refund. This should handle firing the correct hooks to |
|
411 | + * indicate |
|
412 | + * what exactly happened and updating the transaction appropriately). This |
|
413 | + * could be integrated directly into EE_Transaction upon save, but we want |
|
414 | + * this logic to be separate from 'normal' plain-jane saving and updating |
|
415 | + * of transactions and payments, and to be tied to payment processing. |
|
416 | + * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
417 | + * of previous code to decide whether or not to save (because the payment passed into |
|
418 | + * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
419 | + * in which case we only want that payment object for some temporary usage during this request, |
|
420 | + * but we don't want it to be saved). |
|
421 | + * |
|
422 | + * @param EE_Transaction|int $transaction |
|
423 | + * @param EE_Payment $payment |
|
424 | + * @param boolean $update_txn |
|
425 | + * whether or not to call |
|
426 | + * EE_Transaction_Processor:: |
|
427 | + * update_transaction_and_registrations_after_checkout_or_payment() |
|
428 | + * (you can save 1 DB query if you know you're going |
|
429 | + * to save it later instead) |
|
430 | + * @param bool $IPN |
|
431 | + * if processing IPNs or other similar payment |
|
432 | + * related activities that occur in alternate |
|
433 | + * requests than the main one that is processing the |
|
434 | + * TXN, then set this to true to check whether the |
|
435 | + * TXN is locked before updating |
|
436 | + * @throws \EE_Error |
|
437 | + */ |
|
438 | + public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
439 | + { |
|
440 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
441 | + /** @type EE_Transaction $transaction */ |
|
442 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
443 | + // can we freely update the TXN at this moment? |
|
444 | + if ($IPN && $transaction->is_locked()) { |
|
445 | + // don't update the transaction at this exact moment |
|
446 | + // because the TXN is active in another request |
|
447 | + EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
448 | + time(), |
|
449 | + $transaction->ID(), |
|
450 | + $payment->ID() |
|
451 | + ); |
|
452 | + } else { |
|
453 | + // verify payment and that it has been saved |
|
454 | + if ($payment instanceof EE_Payment && $payment->ID()) { |
|
455 | + if ( |
|
456 | + $payment->payment_method() instanceof EE_Payment_Method |
|
457 | + && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
458 | + ) { |
|
459 | + $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
460 | + // update TXN registrations with payment info |
|
461 | + $this->process_registration_payments($transaction, $payment); |
|
462 | + } |
|
463 | + $do_action = $payment->just_approved() |
|
464 | + ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
465 | + : $do_action; |
|
466 | + } else { |
|
467 | + // send out notifications |
|
468 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
469 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
470 | + } |
|
471 | + if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
472 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
473 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
474 | + // set new value for total paid |
|
475 | + $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
476 | + // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
477 | + if ($update_txn) { |
|
478 | + $this->_post_payment_processing($transaction, $payment, $IPN); |
|
479 | + } |
|
480 | + } |
|
481 | + // granular hook for others to use. |
|
482 | + do_action($do_action, $transaction, $payment); |
|
483 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
484 | + //global hook for others to use. |
|
485 | + do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
486 | + } |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * update registrations REG_paid field after successful payment and link registrations with payment |
|
493 | + * |
|
494 | + * @param EE_Transaction $transaction |
|
495 | + * @param EE_Payment $payment |
|
496 | + * @param EE_Registration[] $registrations |
|
497 | + * @throws \EE_Error |
|
498 | + */ |
|
499 | + public function process_registration_payments( |
|
500 | + EE_Transaction $transaction, |
|
501 | + EE_Payment $payment, |
|
502 | + $registrations = array() |
|
503 | + ) { |
|
504 | + // only process if payment was successful |
|
505 | + if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
506 | + return; |
|
507 | + } |
|
508 | + //EEM_Registration::instance()->show_next_x_db_queries(); |
|
509 | + if (empty($registrations)) { |
|
510 | + // find registrations with monies owing that can receive a payment |
|
511 | + $registrations = $transaction->registrations( |
|
512 | + array( |
|
513 | + array( |
|
514 | + // only these reg statuses can receive payments |
|
515 | + 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
516 | + 'REG_final_price' => array('!=', 0), |
|
517 | + 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
518 | + ), |
|
519 | + ) |
|
520 | + ); |
|
521 | + } |
|
522 | + // still nothing ??!?? |
|
523 | + if (empty($registrations)) { |
|
524 | + return; |
|
525 | + } |
|
526 | + // todo: break out the following logic into a separate strategy class |
|
527 | + // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
528 | + // todo: which would apply payments using the capitalist "first come first paid" approach |
|
529 | + // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
530 | + // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
531 | + // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
532 | + $refund = $payment->is_a_refund(); |
|
533 | + // how much is available to apply to registrations? |
|
534 | + $available_payment_amount = abs($payment->amount()); |
|
535 | + foreach ($registrations as $registration) { |
|
536 | + if ($registration instanceof EE_Registration) { |
|
537 | + // nothing left? |
|
538 | + if ($available_payment_amount <= 0) { |
|
539 | + break; |
|
540 | + } |
|
541 | + if ($refund) { |
|
542 | + $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount); |
|
543 | + } else { |
|
544 | + $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount); |
|
545 | + } |
|
546 | + } |
|
547 | + } |
|
548 | + if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) { |
|
549 | + EE_Error::add_attention( |
|
550 | + sprintf( |
|
551 | + __('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', |
|
552 | + 'event_espresso'), |
|
553 | + EEH_Template::format_currency($available_payment_amount), |
|
554 | + implode(', ', array_keys($registrations)), |
|
555 | + '<br/>', |
|
556 | + EEH_Template::format_currency($payment->amount()) |
|
557 | + ), |
|
558 | + __FILE__, __FUNCTION__, __LINE__ |
|
559 | + ); |
|
560 | + } |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * update registration REG_paid field after successful payment and link registration with payment |
|
567 | + * |
|
568 | + * @param EE_Registration $registration |
|
569 | + * @param EE_Payment $payment |
|
570 | + * @param float $available_payment_amount |
|
571 | + * @return float |
|
572 | + * @throws \EE_Error |
|
573 | + */ |
|
574 | + public function process_registration_payment( |
|
575 | + EE_Registration $registration, |
|
576 | + EE_Payment $payment, |
|
577 | + $available_payment_amount = 0.00 |
|
578 | + ) { |
|
579 | + $owing = $registration->final_price() - $registration->paid(); |
|
580 | + if ($owing > 0) { |
|
581 | + // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
582 | + $payment_amount = min($available_payment_amount, $owing); |
|
583 | + // update $available_payment_amount |
|
584 | + $available_payment_amount -= $payment_amount; |
|
585 | + //calculate and set new REG_paid |
|
586 | + $registration->set_paid($registration->paid() + $payment_amount); |
|
587 | + // now save it |
|
588 | + $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
589 | + } |
|
590 | + return $available_payment_amount; |
|
591 | + } |
|
592 | + |
|
593 | + |
|
594 | + |
|
595 | + /** |
|
596 | + * update registration REG_paid field after successful payment and link registration with payment |
|
597 | + * |
|
598 | + * @param EE_Registration $registration |
|
599 | + * @param EE_Payment $payment |
|
600 | + * @param float $payment_amount |
|
601 | + * @return void |
|
602 | + * @throws \EE_Error |
|
603 | + */ |
|
604 | + protected function _apply_registration_payment( |
|
605 | + EE_Registration $registration, |
|
606 | + EE_Payment $payment, |
|
607 | + $payment_amount = 0.00 |
|
608 | + ) { |
|
609 | + // find any existing reg payment records for this registration and payment |
|
610 | + $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
611 | + array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
612 | + ); |
|
613 | + // if existing registration payment exists |
|
614 | + if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
615 | + // then update that record |
|
616 | + $existing_reg_payment->set_amount($payment_amount); |
|
617 | + $existing_reg_payment->save(); |
|
618 | + } else { |
|
619 | + // or add new relation between registration and payment and set amount |
|
620 | + $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount)); |
|
621 | + // make it stick |
|
622 | + $registration->save(); |
|
623 | + } |
|
624 | + } |
|
625 | + |
|
626 | + |
|
627 | + |
|
628 | + /** |
|
629 | + * update registration REG_paid field after refund and link registration with payment |
|
630 | + * |
|
631 | + * @param EE_Registration $registration |
|
632 | + * @param EE_Payment $payment |
|
633 | + * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
634 | + * @return float |
|
635 | + * @throws \EE_Error |
|
636 | + */ |
|
637 | + public function process_registration_refund( |
|
638 | + EE_Registration $registration, |
|
639 | + EE_Payment $payment, |
|
640 | + $available_refund_amount = 0.00 |
|
641 | + ) { |
|
642 | + //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
643 | + if ($registration->paid() > 0) { |
|
644 | + // ensure $available_refund_amount is NOT negative |
|
645 | + $available_refund_amount = (float)abs($available_refund_amount); |
|
646 | + // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
647 | + $refund_amount = min($available_refund_amount, (float)$registration->paid()); |
|
648 | + // update $available_payment_amount |
|
649 | + $available_refund_amount -= $refund_amount; |
|
650 | + //calculate and set new REG_paid |
|
651 | + $registration->set_paid($registration->paid() - $refund_amount); |
|
652 | + // convert payment amount back to a negative value for storage in the db |
|
653 | + $refund_amount = (float)abs($refund_amount) * -1; |
|
654 | + // now save it |
|
655 | + $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
656 | + } |
|
657 | + return $available_refund_amount; |
|
658 | + } |
|
659 | + |
|
660 | + |
|
661 | + |
|
662 | + /** |
|
663 | + * Process payments and transaction after payment process completed. |
|
664 | + * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
665 | + * if this request happens to be processing an IPN, |
|
666 | + * then we will also set the Payment Options Reg Step to completed, |
|
667 | + * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
668 | + * |
|
669 | + * @param EE_Transaction $transaction |
|
670 | + * @param EE_Payment $payment |
|
671 | + * @param bool $IPN |
|
672 | + * @throws \EE_Error |
|
673 | + */ |
|
674 | + protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
675 | + { |
|
676 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
677 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
678 | + // is the Payment Options Reg Step completed ? |
|
679 | + $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
680 | + // if the Payment Options Reg Step is completed... |
|
681 | + $revisit = $payment_options_step_completed === true ? true : false; |
|
682 | + // then this is kinda sorta a revisit with regards to payments at least |
|
683 | + $transaction_processor->set_revisit($revisit); |
|
684 | + // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
685 | + if ( |
|
686 | + $IPN |
|
687 | + && $payment_options_step_completed !== true |
|
688 | + && ($payment->is_approved() || $payment->is_pending()) |
|
689 | + ) { |
|
690 | + $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
691 | + 'payment_options' |
|
692 | + ); |
|
693 | + } |
|
694 | + // maybe update status, but don't save transaction just yet |
|
695 | + $transaction->update_status_based_on_total_paid(false); |
|
696 | + // check if 'finalize_registration' step has been completed... |
|
697 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
698 | + // if this is an IPN and the final step has not been initiated |
|
699 | + if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
700 | + // and if it hasn't already been set as being started... |
|
701 | + $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
702 | + } |
|
703 | + $transaction->save(); |
|
704 | + // because the above will return false if the final step was not fully completed, we need to check again... |
|
705 | + if ($IPN && $finalized !== false) { |
|
706 | + // and if we are all good to go, then send out notifications |
|
707 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
708 | + //ok, now process the transaction according to the payment |
|
709 | + $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment); |
|
710 | + } |
|
711 | + // DEBUG LOG |
|
712 | + $payment_method = $payment->payment_method(); |
|
713 | + if ($payment_method instanceof EE_Payment_Method) { |
|
714 | + $payment_method_type_obj = $payment_method->type_obj(); |
|
715 | + if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
716 | + $gateway = $payment_method_type_obj->get_gateway(); |
|
717 | + if ($gateway instanceof EE_Gateway) { |
|
718 | + $gateway->log( |
|
719 | + array( |
|
720 | + 'message' => __('Post Payment Transaction Details', 'event_espresso'), |
|
721 | + 'transaction' => $transaction->model_field_array(), |
|
722 | + 'finalized' => $finalized, |
|
723 | + 'IPN' => $IPN, |
|
724 | + 'deliver_notifications' => has_filter( |
|
725 | + 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
726 | + ), |
|
727 | + ), |
|
728 | + $payment |
|
729 | + ); |
|
730 | + } |
|
731 | + } |
|
732 | + } |
|
733 | + } |
|
734 | + |
|
735 | + |
|
736 | + |
|
737 | + /** |
|
738 | + * Force posts to PayPal to use TLS v1.2. See: |
|
739 | + * https://core.trac.wordpress.org/ticket/36320 |
|
740 | + * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
741 | + * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
742 | + * This will affect paypal standard, pro, express, and payflow. |
|
743 | + */ |
|
744 | + public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
745 | + { |
|
746 | + if (strstr($url, 'https://') && strstr($url, '.paypal.com')) { |
|
747 | + //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
748 | + //instead of the constant because it might not be defined |
|
749 | + curl_setopt($handle, CURLOPT_SSLVERSION, 1); |
|
750 | + } |
|
751 | + } |
|
752 | 752 | } |
@@ -163,7 +163,7 @@ |
||
163 | 163 | private function _display_minimum_recommended_php_version_notice() |
164 | 164 | { |
165 | 165 | EE_Error::add_persistent_admin_notice( |
166 | - 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
166 | + 'php_version_'.str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED).'_recommended', |
|
167 | 167 | sprintf( |
168 | 168 | __('Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
169 | 169 | 'event_espresso'), |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -18,150 +18,150 @@ discard block |
||
18 | 18 | { |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * converts a Request to a Response |
|
23 | - * |
|
24 | - * @param EE_Request $request |
|
25 | - * @param EE_Response $response |
|
26 | - * @return EE_Response |
|
27 | - */ |
|
28 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
29 | - { |
|
30 | - $this->_request = $request; |
|
31 | - $this->_response = $response; |
|
32 | - //$this->_response->add_output( "\n\t IN >> " . __CLASS__ ); |
|
33 | - //$this->_response->set_notice( 1, 'hey look at this' ); |
|
34 | - // check required WP version |
|
35 | - if ( ! $this->_minimum_wp_version_required()) { |
|
36 | - $this->_request->un_set('activate', true); |
|
37 | - add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
|
38 | - //$this->_response->add_output( "\n<br />" . 'minimum_wp_version_error' ); |
|
39 | - $this->_response->terminate_request(); |
|
40 | - $this->_response->deactivate_plugin(); |
|
41 | - } |
|
42 | - // check recommended PHP version |
|
43 | - if ( ! $this->_minimum_php_version_recommended()) { |
|
44 | - $this->_display_minimum_recommended_php_version_notice(); |
|
45 | - } |
|
46 | - $this->_response = $this->process_request_stack($this->_request, $this->_response); |
|
47 | - //$this->_response->add_output( "\n\t OUT << " . __CLASS__ ); |
|
48 | - return $this->_response; |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Helper method to assess installed wp version against given values. |
|
54 | - * By default this compares the required minimum version of WP for EE against the installed version of WP |
|
55 | - * |
|
56 | - * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked against) |
|
57 | - * so consider that when sending in your values. |
|
58 | - * |
|
59 | - * @param string $version_to_check |
|
60 | - * @param string $operator |
|
61 | - * @return bool |
|
62 | - */ |
|
63 | - public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
64 | - { |
|
65 | - global $wp_version; |
|
66 | - return version_compare( |
|
67 | - //first account for wp_version being pre-release (like RC, beta etc which are usually in the format like |
|
68 | - //4.7-RC3-39519 |
|
69 | - strpos($wp_version, '-') > 0 ? substr($wp_version, 0, strpos($wp_version, '-')) : $wp_version, |
|
70 | - $version_to_check, |
|
71 | - $operator |
|
72 | - ); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * _minimum_wp_version_required |
|
79 | - * |
|
80 | - * @access private |
|
81 | - * @return boolean |
|
82 | - */ |
|
83 | - private function _minimum_wp_version_required() |
|
84 | - { |
|
85 | - return self::check_wp_version(); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * _check_php_version |
|
92 | - * |
|
93 | - * @access private |
|
94 | - * @param string $min_version |
|
95 | - * @return boolean |
|
96 | - */ |
|
97 | - private function _check_php_version($min_version = EE_MIN_PHP_VER_RECOMMENDED) |
|
98 | - { |
|
99 | - return version_compare(PHP_VERSION, $min_version, '>=') ? true : false; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * _minimum_php_version_recommended |
|
106 | - * |
|
107 | - * @access private |
|
108 | - * @return boolean |
|
109 | - */ |
|
110 | - private function _minimum_php_version_recommended() |
|
111 | - { |
|
112 | - return $this->_check_php_version(EE_MIN_PHP_VER_RECOMMENDED); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * minimum_wp_version_error |
|
119 | - * |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - public function minimum_wp_version_error() |
|
123 | - { |
|
124 | - global $wp_version; |
|
125 | - ?> |
|
21 | + /** |
|
22 | + * converts a Request to a Response |
|
23 | + * |
|
24 | + * @param EE_Request $request |
|
25 | + * @param EE_Response $response |
|
26 | + * @return EE_Response |
|
27 | + */ |
|
28 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
29 | + { |
|
30 | + $this->_request = $request; |
|
31 | + $this->_response = $response; |
|
32 | + //$this->_response->add_output( "\n\t IN >> " . __CLASS__ ); |
|
33 | + //$this->_response->set_notice( 1, 'hey look at this' ); |
|
34 | + // check required WP version |
|
35 | + if ( ! $this->_minimum_wp_version_required()) { |
|
36 | + $this->_request->un_set('activate', true); |
|
37 | + add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
|
38 | + //$this->_response->add_output( "\n<br />" . 'minimum_wp_version_error' ); |
|
39 | + $this->_response->terminate_request(); |
|
40 | + $this->_response->deactivate_plugin(); |
|
41 | + } |
|
42 | + // check recommended PHP version |
|
43 | + if ( ! $this->_minimum_php_version_recommended()) { |
|
44 | + $this->_display_minimum_recommended_php_version_notice(); |
|
45 | + } |
|
46 | + $this->_response = $this->process_request_stack($this->_request, $this->_response); |
|
47 | + //$this->_response->add_output( "\n\t OUT << " . __CLASS__ ); |
|
48 | + return $this->_response; |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Helper method to assess installed wp version against given values. |
|
54 | + * By default this compares the required minimum version of WP for EE against the installed version of WP |
|
55 | + * |
|
56 | + * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked against) |
|
57 | + * so consider that when sending in your values. |
|
58 | + * |
|
59 | + * @param string $version_to_check |
|
60 | + * @param string $operator |
|
61 | + * @return bool |
|
62 | + */ |
|
63 | + public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
64 | + { |
|
65 | + global $wp_version; |
|
66 | + return version_compare( |
|
67 | + //first account for wp_version being pre-release (like RC, beta etc which are usually in the format like |
|
68 | + //4.7-RC3-39519 |
|
69 | + strpos($wp_version, '-') > 0 ? substr($wp_version, 0, strpos($wp_version, '-')) : $wp_version, |
|
70 | + $version_to_check, |
|
71 | + $operator |
|
72 | + ); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * _minimum_wp_version_required |
|
79 | + * |
|
80 | + * @access private |
|
81 | + * @return boolean |
|
82 | + */ |
|
83 | + private function _minimum_wp_version_required() |
|
84 | + { |
|
85 | + return self::check_wp_version(); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * _check_php_version |
|
92 | + * |
|
93 | + * @access private |
|
94 | + * @param string $min_version |
|
95 | + * @return boolean |
|
96 | + */ |
|
97 | + private function _check_php_version($min_version = EE_MIN_PHP_VER_RECOMMENDED) |
|
98 | + { |
|
99 | + return version_compare(PHP_VERSION, $min_version, '>=') ? true : false; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * _minimum_php_version_recommended |
|
106 | + * |
|
107 | + * @access private |
|
108 | + * @return boolean |
|
109 | + */ |
|
110 | + private function _minimum_php_version_recommended() |
|
111 | + { |
|
112 | + return $this->_check_php_version(EE_MIN_PHP_VER_RECOMMENDED); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * minimum_wp_version_error |
|
119 | + * |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + public function minimum_wp_version_error() |
|
123 | + { |
|
124 | + global $wp_version; |
|
125 | + ?> |
|
126 | 126 | <div class="error"> |
127 | 127 | <p> |
128 | 128 | <?php |
129 | - printf( |
|
130 | - __('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', |
|
131 | - 'event_espresso'), |
|
132 | - EE_MIN_WP_VER_REQUIRED, |
|
133 | - $wp_version, |
|
134 | - '<br/>', |
|
135 | - '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>' |
|
136 | - ); |
|
137 | - ?> |
|
129 | + printf( |
|
130 | + __('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', |
|
131 | + 'event_espresso'), |
|
132 | + EE_MIN_WP_VER_REQUIRED, |
|
133 | + $wp_version, |
|
134 | + '<br/>', |
|
135 | + '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>' |
|
136 | + ); |
|
137 | + ?> |
|
138 | 138 | </p> |
139 | 139 | </div> |
140 | 140 | <?php |
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * _display_minimum_recommended_php_version_notice |
|
147 | - * |
|
148 | - * @access private |
|
149 | - * @return void |
|
150 | - */ |
|
151 | - private function _display_minimum_recommended_php_version_notice() |
|
152 | - { |
|
153 | - EE_Error::add_persistent_admin_notice( |
|
154 | - 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
155 | - sprintf( |
|
156 | - __('Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
157 | - 'event_espresso'), |
|
158 | - EE_MIN_PHP_VER_RECOMMENDED, |
|
159 | - PHP_VERSION, |
|
160 | - '<br/>', |
|
161 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
162 | - ) |
|
163 | - ); |
|
164 | - } |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * _display_minimum_recommended_php_version_notice |
|
147 | + * |
|
148 | + * @access private |
|
149 | + * @return void |
|
150 | + */ |
|
151 | + private function _display_minimum_recommended_php_version_notice() |
|
152 | + { |
|
153 | + EE_Error::add_persistent_admin_notice( |
|
154 | + 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
155 | + sprintf( |
|
156 | + __('Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
157 | + 'event_espresso'), |
|
158 | + EE_MIN_PHP_VER_RECOMMENDED, |
|
159 | + PHP_VERSION, |
|
160 | + '<br/>', |
|
161 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
162 | + ) |
|
163 | + ); |
|
164 | + } |
|
165 | 165 | |
166 | 166 | |
167 | 167 | } |
@@ -1,3 +1,3 @@ |
||
1 | 1 | <h2><?php esc_html_e('What is the Event Espresso Messages System?', 'event_espresso'); ?></h2> |
2 | -<p><?php printf( esc_html__('The Event Espresso Messages system is a powerful framework that Event Espresso uses to prepare %1$smessages%2$s for different types of use (message types) and delivered by different %1$smessengers%2$s.', 'event_espresso'), '<strong>', '</strong>' ); ?></p> |
|
2 | +<p><?php printf(esc_html__('The Event Espresso Messages system is a powerful framework that Event Espresso uses to prepare %1$smessages%2$s for different types of use (message types) and delivered by different %1$smessengers%2$s.', 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
3 | 3 | <p><?php esc_html_e('We\'ve intentionally created this framework so that we have as much flexibility as possible for future ideas that we think of (or customers think of) for the kinds of messages that get sent out related to your events.', 'event_espresso'); ?></p> |
4 | 4 | \ No newline at end of file |
@@ -31,35 +31,35 @@ discard block |
||
31 | 31 | <tbody> |
32 | 32 | <tr> |
33 | 33 | <td> |
34 | - <h2><?php printf( esc_html__( 'Hello, %s:', 'event_espresso' ), '[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]' ); ?></h2> |
|
35 | - <p class="lead"><?php printf( esc_html__( 'Your payment was %1$sCANCELLED%2$s for the following transaction and ticket purchases:', 'event_espresso' ), '<strong>', '</strong>'); ?></p> |
|
36 | - <h3><?php esc_html_e( 'Payment Details:', 'event_espresso' ); ?></h3> |
|
34 | + <h2><?php printf(esc_html__('Hello, %s:', 'event_espresso'), '[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]'); ?></h2> |
|
35 | + <p class="lead"><?php printf(esc_html__('Your payment was %1$sCANCELLED%2$s for the following transaction and ticket purchases:', 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
36 | + <h3><?php esc_html_e('Payment Details:', 'event_espresso'); ?></h3> |
|
37 | 37 | <ul> |
38 | 38 | <li> |
39 | - <strong><?php esc_html_e( 'Payment Status:', 'event_espresso' ); ?></strong> [PAYMENT_STATUS] |
|
39 | + <strong><?php esc_html_e('Payment Status:', 'event_espresso'); ?></strong> [PAYMENT_STATUS] |
|
40 | 40 | </li> |
41 | 41 | <li> |
42 | - <strong><?php esc_html_e( 'Transaction ID:', 'event_espresso' ); ?></strong> [TXN_ID] |
|
42 | + <strong><?php esc_html_e('Transaction ID:', 'event_espresso'); ?></strong> [TXN_ID] |
|
43 | 43 | </li> |
44 | 44 | <li> |
45 | - <strong><?php esc_html_e( 'Total Cost:', 'event_espresso' ); ?></strong> [TOTAL_COST] |
|
45 | + <strong><?php esc_html_e('Total Cost:', 'event_espresso'); ?></strong> [TOTAL_COST] |
|
46 | 46 | </li> |
47 | 47 | <li> |
48 | - <strong><?php esc_html_e( 'Payment Method:', 'event_espresso' ); ?></strong> [PAYMENT_GATEWAY] |
|
48 | + <strong><?php esc_html_e('Payment Method:', 'event_espresso'); ?></strong> [PAYMENT_GATEWAY] |
|
49 | 49 | </li> |
50 | 50 | <li> |
51 | - <strong><?php esc_html_e( 'Payment Amount:', 'event_espresso' ); ?></strong> [AMOUNT_PAID] |
|
51 | + <strong><?php esc_html_e('Payment Amount:', 'event_espresso'); ?></strong> [AMOUNT_PAID] |
|
52 | 52 | </li> |
53 | 53 | <li> |
54 | - <strong><?php esc_html_e( 'Amount Due:', 'event_espresso' ); ?></strong> [TOTAL_OWING] |
|
54 | + <strong><?php esc_html_e('Amount Due:', 'event_espresso'); ?></strong> [TOTAL_OWING] |
|
55 | 55 | </li> |
56 | 56 | </ul> |
57 | 57 | <p class="callout"> |
58 | - <?php printf( esc_html__( 'Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso' ), '<a href="[PAYMENT_URL]">', '</a>' ); ?> |
|
58 | + <?php printf(esc_html__('Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso'), '<a href="[PAYMENT_URL]">', '</a>'); ?> |
|
59 | 59 | </p> |
60 | 60 | [EVENT_LIST] |
61 | 61 | <p class="callout"> |
62 | - <?php printf( esc_html__( 'Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso' ), '<a href="[PAYMENT_URL]">', '</a>' ); ?> |
|
62 | + <?php printf(esc_html__('Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso'), '<a href="[PAYMENT_URL]">', '</a>'); ?> |
|
63 | 63 | </p> |
64 | 64 | </td> |
65 | 65 | </tr> |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | <tbody> |
85 | 85 | <tr> |
86 | 86 | <td> |
87 | - <h3><?php esc_html_e( 'Connect with Us:', 'event_espresso' ); ?></h3> |
|
88 | - <a class="soc-btn fb" href="[CO_FACEBOOK_URL]"><?php esc_html_e( 'Facebook', 'event_espresso' ); ?></a> |
|
89 | - <a class="soc-btn tw" href="[CO_TWITTER_URL]"><?php esc_html_e( 'Twitter', 'event_espresso' ); ?></a> |
|
90 | - <a class="soc-btn gp" href="[CO_GOOGLE_URL]"><?php esc_html_e( 'Google+', 'event_espresso' ); ?></a> |
|
87 | + <h3><?php esc_html_e('Connect with Us:', 'event_espresso'); ?></h3> |
|
88 | + <a class="soc-btn fb" href="[CO_FACEBOOK_URL]"><?php esc_html_e('Facebook', 'event_espresso'); ?></a> |
|
89 | + <a class="soc-btn tw" href="[CO_TWITTER_URL]"><?php esc_html_e('Twitter', 'event_espresso'); ?></a> |
|
90 | + <a class="soc-btn gp" href="[CO_GOOGLE_URL]"><?php esc_html_e('Google+', 'event_espresso'); ?></a> |
|
91 | 91 | </td> |
92 | 92 | </tr> |
93 | 93 | </tbody> |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | <tbody> |
98 | 98 | <tr> |
99 | 99 | <td> |
100 | - <h3><?php esc_html_e( 'Contact Info:', 'event_espresso' ); ?></h3> |
|
101 | - <?php esc_html_e( 'Phone:', 'event_espresso' ); ?> <strong>[CO_PHONE]</strong> |
|
102 | - <?php esc_html_e( 'Email:', 'event_espresso' ); ?> <strong><a href="mailto:[CO_EMAIL]" target="_blank">[CO_EMAIL]</a></strong> |
|
100 | + <h3><?php esc_html_e('Contact Info:', 'event_espresso'); ?></h3> |
|
101 | + <?php esc_html_e('Phone:', 'event_espresso'); ?> <strong>[CO_PHONE]</strong> |
|
102 | + <?php esc_html_e('Email:', 'event_espresso'); ?> <strong><a href="mailto:[CO_EMAIL]" target="_blank">[CO_EMAIL]</a></strong> |
|
103 | 103 | </td> |
104 | 104 | </tr> |
105 | 105 | </tbody> |
@@ -31,35 +31,35 @@ discard block |
||
31 | 31 | <tbody> |
32 | 32 | <tr> |
33 | 33 | <td> |
34 | - <h2><?php printf( esc_html__( 'Hello, %s:', 'event_espresso' ), '[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]' ); ?></h2> |
|
35 | - <p class="lead"><?php printf( esc_html__( 'Your payment was %1$sDECLINED%2$s for the following transaction and ticket purchases:', 'event_espresso' ), '<strong>', '</strong>') ?></p> |
|
36 | - <h3><?php esc_html_e( 'Payment Details:', 'event_espresso' ); ?></h3> |
|
34 | + <h2><?php printf(esc_html__('Hello, %s:', 'event_espresso'), '[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]'); ?></h2> |
|
35 | + <p class="lead"><?php printf(esc_html__('Your payment was %1$sDECLINED%2$s for the following transaction and ticket purchases:', 'event_espresso'), '<strong>', '</strong>') ?></p> |
|
36 | + <h3><?php esc_html_e('Payment Details:', 'event_espresso'); ?></h3> |
|
37 | 37 | <ul> |
38 | 38 | <li> |
39 | - <strong><?php esc_html_e( 'Payment Status:', 'event_espresso' ); ?></strong> [PAYMENT_STATUS] |
|
39 | + <strong><?php esc_html_e('Payment Status:', 'event_espresso'); ?></strong> [PAYMENT_STATUS] |
|
40 | 40 | </li> |
41 | 41 | <li> |
42 | - <strong><?php esc_html_e( 'Transaction ID:', 'event_espresso' ); ?></strong> [TXN_ID] |
|
42 | + <strong><?php esc_html_e('Transaction ID:', 'event_espresso'); ?></strong> [TXN_ID] |
|
43 | 43 | </li> |
44 | 44 | <li> |
45 | - <strong><?php esc_html_e( 'Total Cost:', 'event_espresso' ); ?></strong> [TOTAL_COST] |
|
45 | + <strong><?php esc_html_e('Total Cost:', 'event_espresso'); ?></strong> [TOTAL_COST] |
|
46 | 46 | </li> |
47 | 47 | <li> |
48 | - <strong><?php esc_html_e( 'Payment Method:', 'event_espresso' ); ?></strong> [PAYMENT_GATEWAY] |
|
48 | + <strong><?php esc_html_e('Payment Method:', 'event_espresso'); ?></strong> [PAYMENT_GATEWAY] |
|
49 | 49 | </li> |
50 | 50 | <li> |
51 | - <strong><?php esc_html_e( 'Payment Amount:', 'event_espresso' ); ?></strong> [AMOUNT_PAID] |
|
51 | + <strong><?php esc_html_e('Payment Amount:', 'event_espresso'); ?></strong> [AMOUNT_PAID] |
|
52 | 52 | </li> |
53 | 53 | <li> |
54 | - <strong><?php esc_html_e( 'Amount Due:', 'event_espresso' ); ?></strong> [TOTAL_OWING] |
|
54 | + <strong><?php esc_html_e('Amount Due:', 'event_espresso'); ?></strong> [TOTAL_OWING] |
|
55 | 55 | </li> |
56 | 56 | </ul> |
57 | 57 | <p class="callout"> |
58 | - <?php printf( esc_html__( 'Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso' ), '<a href="[PAYMENT_URL]">', '</a>' ); ?> |
|
58 | + <?php printf(esc_html__('Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso'), '<a href="[PAYMENT_URL]">', '</a>'); ?> |
|
59 | 59 | </p> |
60 | 60 | [EVENT_LIST] |
61 | 61 | <p class="callout"> |
62 | - <?php printf( esc_html__( 'Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso' ), '<a href="[PAYMENT_URL]">', '</a>' ); ?> |
|
62 | + <?php printf(esc_html__('Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso'), '<a href="[PAYMENT_URL]">', '</a>'); ?> |
|
63 | 63 | </p> |
64 | 64 | </td> |
65 | 65 | </tr> |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | <tbody> |
85 | 85 | <tr> |
86 | 86 | <td> |
87 | - <h3><?php esc_html_e( 'Connect with Us:', 'event_espresso' ); ?></h3> |
|
88 | - <a class="soc-btn fb" href="[CO_FACEBOOK_URL]"><?php esc_html_e( 'Facebook', 'event_espresso' ); ?></a> |
|
89 | - <a class="soc-btn tw" href="[CO_TWITTER_URL]"><?php esc_html_e( 'Twitter', 'event_espresso' ); ?></a> |
|
90 | - <a class="soc-btn gp" href="[CO_GOOGLE_URL]"><?php esc_html_e( 'Google+', 'event_espresso' ); ?></a> |
|
87 | + <h3><?php esc_html_e('Connect with Us:', 'event_espresso'); ?></h3> |
|
88 | + <a class="soc-btn fb" href="[CO_FACEBOOK_URL]"><?php esc_html_e('Facebook', 'event_espresso'); ?></a> |
|
89 | + <a class="soc-btn tw" href="[CO_TWITTER_URL]"><?php esc_html_e('Twitter', 'event_espresso'); ?></a> |
|
90 | + <a class="soc-btn gp" href="[CO_GOOGLE_URL]"><?php esc_html_e('Google+', 'event_espresso'); ?></a> |
|
91 | 91 | </td> |
92 | 92 | </tr> |
93 | 93 | </tbody> |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | <tbody> |
98 | 98 | <tr> |
99 | 99 | <td> |
100 | - <h3><?php esc_html_e( 'Contact Info:', 'event_espresso' ); ?></h3> |
|
101 | - <?php esc_html_e( 'Phone:', 'event_espresso' ); ?> <strong>[CO_PHONE]</strong> |
|
102 | - <?php esc_html_e( 'Email:', 'event_espresso' ); ?> <strong><a href="mailto:[CO_EMAIL]" target="_blank">[CO_EMAIL]</a></strong> |
|
100 | + <h3><?php esc_html_e('Contact Info:', 'event_espresso'); ?></h3> |
|
101 | + <?php esc_html_e('Phone:', 'event_espresso'); ?> <strong>[CO_PHONE]</strong> |
|
102 | + <?php esc_html_e('Email:', 'event_espresso'); ?> <strong><a href="mailto:[CO_EMAIL]" target="_blank">[CO_EMAIL]</a></strong> |
|
103 | 103 | </td> |
104 | 104 | </tr> |
105 | 105 | </tbody> |
@@ -364,7 +364,7 @@ |
||
364 | 364 | $iterations = ceil($length / 40); |
365 | 365 | $random_string = ''; |
366 | 366 | for ($i = 0; $i < $iterations; $i++) { |
367 | - $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
367 | + $random_string .= sha1(microtime(true).mt_rand(10000, 90000)); |
|
368 | 368 | } |
369 | 369 | $random_string = substr($random_string, 0, $length); |
370 | 370 | return $random_string; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('No direct script access allowed'); |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -18,356 +18,355 @@ discard block |
||
18 | 18 | class EE_Encryption |
19 | 19 | { |
20 | 20 | |
21 | - // instance of the EE_Encryption object |
|
22 | - protected static $_instance; |
|
23 | - |
|
24 | - protected $_encryption_key; |
|
25 | - |
|
26 | - protected $_use_mcrypt = true; |
|
27 | - |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * private constructor to prevent direct creation |
|
32 | - |
|
33 | - */ |
|
34 | - private function __construct() |
|
35 | - { |
|
36 | - define('ESPRESSO_ENCRYPT', true); |
|
37 | - if ( ! function_exists('mcrypt_encrypt')) { |
|
38 | - $this->_use_mcrypt = false; |
|
39 | - } |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * singleton method used to instantiate class object |
|
46 | - * |
|
47 | - * @access public |
|
48 | - * @return \EE_Encryption |
|
49 | - */ |
|
50 | - public static function instance() |
|
51 | - { |
|
52 | - // check if class object is instantiated |
|
53 | - if ( ! self::$_instance instanceof EE_Encryption) { |
|
54 | - self::$_instance = new self(); |
|
55 | - } |
|
56 | - return self::$_instance; |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * get encryption key |
|
63 | - * |
|
64 | - * @access public |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function get_encryption_key() |
|
68 | - { |
|
69 | - // if encryption key has not been set |
|
70 | - if (empty($this->_encryption_key)) { |
|
71 | - // retrieve encryption_key from db |
|
72 | - $this->_encryption_key = get_option('ee_encryption_key', ''); |
|
73 | - // WHAT?? No encryption_key in the db ?? |
|
74 | - if ($this->_encryption_key === '') { |
|
75 | - // let's make one. And md5 it to make it just the right size for a key |
|
76 | - $new_key = md5($this->generate_random_string()); |
|
77 | - // now save it to the db for later |
|
78 | - add_option('ee_encryption_key', $new_key); |
|
79 | - // here's the key - FINALLY ! |
|
80 | - $this->_encryption_key = $new_key; |
|
81 | - } |
|
82 | - } |
|
83 | - return $this->_encryption_key; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * encrypts data |
|
90 | - * |
|
91 | - * @access public |
|
92 | - * @param string $text_string - the text to be encrypted |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function encrypt($text_string = '') |
|
96 | - { |
|
97 | - // you give me nothing??? GET OUT ! |
|
98 | - if (empty($text_string)) { |
|
99 | - return $text_string; |
|
100 | - } |
|
101 | - if ($this->_use_mcrypt) { |
|
102 | - $encrypted_text = $this->m_encrypt($text_string); |
|
103 | - } else { |
|
104 | - $encrypted_text = $this->acme_encrypt($text_string); |
|
105 | - } |
|
106 | - return $encrypted_text; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * decrypts data |
|
113 | - * |
|
114 | - * @access public |
|
115 | - * @param string $encrypted_text - the text to be decrypted |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - public function decrypt($encrypted_text = '') |
|
119 | - { |
|
120 | - // you give me nothing??? GET OUT ! |
|
121 | - if (empty($encrypted_text)) { |
|
122 | - return $encrypted_text; |
|
123 | - } |
|
124 | - // if PHP's mcrypt functions are installed then we'll use them |
|
125 | - if ($this->_use_mcrypt) { |
|
126 | - $decrypted_text = $this->m_decrypt($encrypted_text); |
|
127 | - } else { |
|
128 | - $decrypted_text = $this->acme_decrypt($encrypted_text); |
|
129 | - } |
|
130 | - return $decrypted_text; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * encodes string with PHP's base64 encoding |
|
137 | - * @source http://php.net/manual/en/function.base64-encode.php |
|
138 | - * |
|
139 | - * @param string $text_string |
|
140 | - * @internal param $string - the text to be encoded |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function base64_string_encode($text_string = '') |
|
144 | - { |
|
145 | - // you give me nothing??? GET OUT ! |
|
146 | - if (empty($text_string) || ! function_exists('base64_encode')) { |
|
147 | - return $text_string; |
|
148 | - } |
|
149 | - // encode |
|
150 | - return base64_encode($text_string); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * decodes string that has been encoded with PHP's base64 encoding |
|
157 | - * @source http://php.net/manual/en/function.base64-encode.php |
|
158 | - * |
|
159 | - * @param string $encoded_string |
|
160 | - * @internal param $string - the text to be decoded |
|
161 | - * @return string |
|
162 | - */ |
|
163 | - public function base64_string_decode($encoded_string = '') |
|
164 | - { |
|
165 | - // you give me nothing??? GET OUT ! |
|
166 | - if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
167 | - return $encoded_string; |
|
168 | - } |
|
169 | - // decode |
|
170 | - return base64_decode($encoded_string); |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * encodes url string with PHP's base64 encoding |
|
177 | - * @source http://php.net/manual/en/function.base64-encode.php |
|
178 | - * |
|
179 | - * @access public |
|
180 | - * @param string $text_string |
|
181 | - * @internal param $string - the text to be encoded |
|
182 | - * @return string |
|
183 | - */ |
|
184 | - public function base64_url_encode($text_string = '') |
|
185 | - { |
|
186 | - // you give me nothing??? GET OUT ! |
|
187 | - if (empty($text_string) || ! function_exists('base64_encode')) { |
|
188 | - return $text_string; |
|
189 | - } |
|
190 | - // encode |
|
191 | - $encoded_string = base64_encode($text_string); |
|
192 | - // remove chars to make encoding more URL friendly |
|
193 | - return strtr($encoded_string, '+/=', '-_,'); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * decodes url string that has been encoded with PHP's base64 encoding |
|
200 | - * @source http://php.net/manual/en/function.base64-encode.php |
|
201 | - * |
|
202 | - * @access public |
|
203 | - * @param string $encoded_string |
|
204 | - * @internal param $string - the text to be decoded |
|
205 | - * @return string |
|
206 | - */ |
|
207 | - public function base64_url_decode($encoded_string = '') |
|
208 | - { |
|
209 | - // you give me nothing??? GET OUT ! |
|
210 | - if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
211 | - return $encoded_string; |
|
212 | - } |
|
213 | - // replace previously removed characters |
|
214 | - $encoded_string = strtr($encoded_string, '-_,', '+/='); |
|
215 | - // decode |
|
216 | - return base64_decode($encoded_string); |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * encrypts data using PHP's mcrypt functions |
|
223 | - * |
|
224 | - * @access private |
|
225 | - * @param string $text_string |
|
226 | - * @internal param $string - the text to be encrypted |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - private function m_encrypt($text_string = '') |
|
230 | - { |
|
231 | - // you give me nothing??? GET OUT ! |
|
232 | - if (empty($text_string)) { |
|
233 | - return $text_string; |
|
234 | - } |
|
235 | - // get the initialization vector size |
|
236 | - $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
237 | - // initialization vector |
|
238 | - $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
239 | - // encrypt it |
|
240 | - $encrypted_text = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->get_encryption_key(), $text_string, MCRYPT_MODE_ECB, $iv); |
|
241 | - // trim and maybe encode |
|
242 | - return function_exists('base64_encode') ? trim(base64_encode($encrypted_text)) : trim($encrypted_text); |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * decrypts data that has been encrypted with PHP's mcrypt functions |
|
249 | - * |
|
250 | - * @access private |
|
251 | - * @param string $encrypted_text |
|
252 | - * @internal param $string - the text to be decrypted |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - private function m_decrypt($encrypted_text = '') |
|
256 | - { |
|
257 | - // you give me nothing??? GET OUT ! |
|
258 | - if (empty($encrypted_text)) { |
|
259 | - return $encrypted_text; |
|
260 | - } |
|
261 | - // decode |
|
262 | - $encrypted_text = $this->valid_base_64($encrypted_text) ? base64_decode($encrypted_text) : $encrypted_text; |
|
263 | - // get the initialization vector size |
|
264 | - $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
265 | - $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
266 | - // decrypt it |
|
267 | - $decrypted_text = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->get_encryption_key(), $encrypted_text, MCRYPT_MODE_ECB, $iv); |
|
268 | - $decrypted_text = trim($decrypted_text); |
|
269 | - return $decrypted_text; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * encrypts data for acme servers that didn't bother to install PHP mcrypt |
|
276 | - * |
|
277 | - * @source : http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
278 | - * @access private |
|
279 | - * @param string $text_string |
|
280 | - * @internal param $string - the text to be decrypted |
|
281 | - * @return string |
|
282 | - */ |
|
283 | - private function acme_encrypt($text_string = '') |
|
284 | - { |
|
285 | - // you give me nothing??? GET OUT ! |
|
286 | - if (empty($text_string)) { |
|
287 | - return $text_string; |
|
288 | - } |
|
289 | - $key_bits = str_split(str_pad('', strlen($text_string), $this->get_encryption_key(), STR_PAD_RIGHT)); |
|
290 | - $string_bits = str_split($text_string); |
|
291 | - foreach ($string_bits as $k => $v) { |
|
292 | - $temp = ord($v) + ord($key_bits[$k]); |
|
293 | - $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp); |
|
294 | - } |
|
295 | - return function_exists('base64_encode') ? base64_encode(implode('', $string_bits)) : implode('', $string_bits); |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * decrypts data for acme servers that didn't bother to install PHP mcrypt |
|
302 | - * |
|
303 | - * @source : http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
304 | - * @param string $encrypted_text the text to be decrypted |
|
305 | - * @return string |
|
306 | - */ |
|
307 | - private function acme_decrypt($encrypted_text = '') |
|
308 | - { |
|
309 | - // you give me nothing??? GET OUT ! |
|
310 | - if (empty($encrypted_text)) { |
|
311 | - return $encrypted_text; |
|
312 | - } |
|
313 | - // decode the data ? |
|
314 | - $encrypted_text = $this->valid_base_64($encrypted_text) ? base64_decode($encrypted_text) : $encrypted_text; |
|
315 | - $key_bits = str_split(str_pad('', strlen($encrypted_text), $this->get_encryption_key(), STR_PAD_RIGHT)); |
|
316 | - $string_bits = str_split($encrypted_text); |
|
317 | - foreach ($string_bits as $k => $v) { |
|
318 | - $temp = ord($v) - ord($key_bits[$k]); |
|
319 | - $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp); |
|
320 | - } |
|
321 | - return implode('', $string_bits); |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906 |
|
328 | - * @param $string |
|
329 | - * @return bool |
|
330 | - */ |
|
331 | - private function valid_base_64($string) |
|
332 | - { |
|
333 | - // ensure data is a string |
|
334 | - if ( ! is_string($string) || ! function_exists('base64_decode')) { |
|
335 | - return false; |
|
336 | - } |
|
337 | - $decoded = base64_decode($string, true); |
|
338 | - // Check if there is no invalid character in string |
|
339 | - if ( ! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
340 | - return false; |
|
341 | - } |
|
342 | - // Decode the string in strict mode and send the response |
|
343 | - if ( ! base64_decode($string, true)) { |
|
344 | - return false; |
|
345 | - } |
|
346 | - // Encode and compare it to original one |
|
347 | - return base64_encode($decoded) === $string; |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * generate random string |
|
354 | - * |
|
355 | - * @source : http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php |
|
356 | - * @access public |
|
357 | - * @param int $length |
|
358 | - * @internal param $string - number of characters for random string |
|
359 | - * @return string |
|
360 | - */ |
|
361 | - public function generate_random_string($length = 40) |
|
362 | - { |
|
363 | - $iterations = ceil($length / 40); |
|
364 | - $random_string = ''; |
|
365 | - for ($i = 0; $i < $iterations; $i++) { |
|
366 | - $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
367 | - } |
|
368 | - $random_string = substr($random_string, 0, $length); |
|
369 | - return $random_string; |
|
370 | - } |
|
21 | + // instance of the EE_Encryption object |
|
22 | + protected static $_instance; |
|
23 | + |
|
24 | + protected $_encryption_key; |
|
25 | + |
|
26 | + protected $_use_mcrypt = true; |
|
27 | + |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * private constructor to prevent direct creation |
|
32 | + */ |
|
33 | + private function __construct() |
|
34 | + { |
|
35 | + define('ESPRESSO_ENCRYPT', true); |
|
36 | + if ( ! function_exists('mcrypt_encrypt')) { |
|
37 | + $this->_use_mcrypt = false; |
|
38 | + } |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * singleton method used to instantiate class object |
|
45 | + * |
|
46 | + * @access public |
|
47 | + * @return \EE_Encryption |
|
48 | + */ |
|
49 | + public static function instance() |
|
50 | + { |
|
51 | + // check if class object is instantiated |
|
52 | + if ( ! self::$_instance instanceof EE_Encryption) { |
|
53 | + self::$_instance = new self(); |
|
54 | + } |
|
55 | + return self::$_instance; |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * get encryption key |
|
62 | + * |
|
63 | + * @access public |
|
64 | + * @return string |
|
65 | + */ |
|
66 | + public function get_encryption_key() |
|
67 | + { |
|
68 | + // if encryption key has not been set |
|
69 | + if (empty($this->_encryption_key)) { |
|
70 | + // retrieve encryption_key from db |
|
71 | + $this->_encryption_key = get_option('ee_encryption_key', ''); |
|
72 | + // WHAT?? No encryption_key in the db ?? |
|
73 | + if ($this->_encryption_key === '') { |
|
74 | + // let's make one. And md5 it to make it just the right size for a key |
|
75 | + $new_key = md5($this->generate_random_string()); |
|
76 | + // now save it to the db for later |
|
77 | + add_option('ee_encryption_key', $new_key); |
|
78 | + // here's the key - FINALLY ! |
|
79 | + $this->_encryption_key = $new_key; |
|
80 | + } |
|
81 | + } |
|
82 | + return $this->_encryption_key; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * encrypts data |
|
89 | + * |
|
90 | + * @access public |
|
91 | + * @param string $text_string - the text to be encrypted |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function encrypt($text_string = '') |
|
95 | + { |
|
96 | + // you give me nothing??? GET OUT ! |
|
97 | + if (empty($text_string)) { |
|
98 | + return $text_string; |
|
99 | + } |
|
100 | + if ($this->_use_mcrypt) { |
|
101 | + $encrypted_text = $this->m_encrypt($text_string); |
|
102 | + } else { |
|
103 | + $encrypted_text = $this->acme_encrypt($text_string); |
|
104 | + } |
|
105 | + return $encrypted_text; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * decrypts data |
|
112 | + * |
|
113 | + * @access public |
|
114 | + * @param string $encrypted_text - the text to be decrypted |
|
115 | + * @return string |
|
116 | + */ |
|
117 | + public function decrypt($encrypted_text = '') |
|
118 | + { |
|
119 | + // you give me nothing??? GET OUT ! |
|
120 | + if (empty($encrypted_text)) { |
|
121 | + return $encrypted_text; |
|
122 | + } |
|
123 | + // if PHP's mcrypt functions are installed then we'll use them |
|
124 | + if ($this->_use_mcrypt) { |
|
125 | + $decrypted_text = $this->m_decrypt($encrypted_text); |
|
126 | + } else { |
|
127 | + $decrypted_text = $this->acme_decrypt($encrypted_text); |
|
128 | + } |
|
129 | + return $decrypted_text; |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * encodes string with PHP's base64 encoding |
|
136 | + * @source http://php.net/manual/en/function.base64-encode.php |
|
137 | + * |
|
138 | + * @param string $text_string |
|
139 | + * @internal param $string - the text to be encoded |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function base64_string_encode($text_string = '') |
|
143 | + { |
|
144 | + // you give me nothing??? GET OUT ! |
|
145 | + if (empty($text_string) || ! function_exists('base64_encode')) { |
|
146 | + return $text_string; |
|
147 | + } |
|
148 | + // encode |
|
149 | + return base64_encode($text_string); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * decodes string that has been encoded with PHP's base64 encoding |
|
156 | + * @source http://php.net/manual/en/function.base64-encode.php |
|
157 | + * |
|
158 | + * @param string $encoded_string |
|
159 | + * @internal param $string - the text to be decoded |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + public function base64_string_decode($encoded_string = '') |
|
163 | + { |
|
164 | + // you give me nothing??? GET OUT ! |
|
165 | + if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
166 | + return $encoded_string; |
|
167 | + } |
|
168 | + // decode |
|
169 | + return base64_decode($encoded_string); |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * encodes url string with PHP's base64 encoding |
|
176 | + * @source http://php.net/manual/en/function.base64-encode.php |
|
177 | + * |
|
178 | + * @access public |
|
179 | + * @param string $text_string |
|
180 | + * @internal param $string - the text to be encoded |
|
181 | + * @return string |
|
182 | + */ |
|
183 | + public function base64_url_encode($text_string = '') |
|
184 | + { |
|
185 | + // you give me nothing??? GET OUT ! |
|
186 | + if (empty($text_string) || ! function_exists('base64_encode')) { |
|
187 | + return $text_string; |
|
188 | + } |
|
189 | + // encode |
|
190 | + $encoded_string = base64_encode($text_string); |
|
191 | + // remove chars to make encoding more URL friendly |
|
192 | + return strtr($encoded_string, '+/=', '-_,'); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * decodes url string that has been encoded with PHP's base64 encoding |
|
199 | + * @source http://php.net/manual/en/function.base64-encode.php |
|
200 | + * |
|
201 | + * @access public |
|
202 | + * @param string $encoded_string |
|
203 | + * @internal param $string - the text to be decoded |
|
204 | + * @return string |
|
205 | + */ |
|
206 | + public function base64_url_decode($encoded_string = '') |
|
207 | + { |
|
208 | + // you give me nothing??? GET OUT ! |
|
209 | + if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
210 | + return $encoded_string; |
|
211 | + } |
|
212 | + // replace previously removed characters |
|
213 | + $encoded_string = strtr($encoded_string, '-_,', '+/='); |
|
214 | + // decode |
|
215 | + return base64_decode($encoded_string); |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * encrypts data using PHP's mcrypt functions |
|
222 | + * |
|
223 | + * @access private |
|
224 | + * @param string $text_string |
|
225 | + * @internal param $string - the text to be encrypted |
|
226 | + * @return string |
|
227 | + */ |
|
228 | + private function m_encrypt($text_string = '') |
|
229 | + { |
|
230 | + // you give me nothing??? GET OUT ! |
|
231 | + if (empty($text_string)) { |
|
232 | + return $text_string; |
|
233 | + } |
|
234 | + // get the initialization vector size |
|
235 | + $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
236 | + // initialization vector |
|
237 | + $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
238 | + // encrypt it |
|
239 | + $encrypted_text = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->get_encryption_key(), $text_string, MCRYPT_MODE_ECB, $iv); |
|
240 | + // trim and maybe encode |
|
241 | + return function_exists('base64_encode') ? trim(base64_encode($encrypted_text)) : trim($encrypted_text); |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * decrypts data that has been encrypted with PHP's mcrypt functions |
|
248 | + * |
|
249 | + * @access private |
|
250 | + * @param string $encrypted_text |
|
251 | + * @internal param $string - the text to be decrypted |
|
252 | + * @return string |
|
253 | + */ |
|
254 | + private function m_decrypt($encrypted_text = '') |
|
255 | + { |
|
256 | + // you give me nothing??? GET OUT ! |
|
257 | + if (empty($encrypted_text)) { |
|
258 | + return $encrypted_text; |
|
259 | + } |
|
260 | + // decode |
|
261 | + $encrypted_text = $this->valid_base_64($encrypted_text) ? base64_decode($encrypted_text) : $encrypted_text; |
|
262 | + // get the initialization vector size |
|
263 | + $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
264 | + $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
265 | + // decrypt it |
|
266 | + $decrypted_text = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->get_encryption_key(), $encrypted_text, MCRYPT_MODE_ECB, $iv); |
|
267 | + $decrypted_text = trim($decrypted_text); |
|
268 | + return $decrypted_text; |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * encrypts data for acme servers that didn't bother to install PHP mcrypt |
|
275 | + * |
|
276 | + * @source : http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
277 | + * @access private |
|
278 | + * @param string $text_string |
|
279 | + * @internal param $string - the text to be decrypted |
|
280 | + * @return string |
|
281 | + */ |
|
282 | + private function acme_encrypt($text_string = '') |
|
283 | + { |
|
284 | + // you give me nothing??? GET OUT ! |
|
285 | + if (empty($text_string)) { |
|
286 | + return $text_string; |
|
287 | + } |
|
288 | + $key_bits = str_split(str_pad('', strlen($text_string), $this->get_encryption_key(), STR_PAD_RIGHT)); |
|
289 | + $string_bits = str_split($text_string); |
|
290 | + foreach ($string_bits as $k => $v) { |
|
291 | + $temp = ord($v) + ord($key_bits[$k]); |
|
292 | + $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp); |
|
293 | + } |
|
294 | + return function_exists('base64_encode') ? base64_encode(implode('', $string_bits)) : implode('', $string_bits); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * decrypts data for acme servers that didn't bother to install PHP mcrypt |
|
301 | + * |
|
302 | + * @source : http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
303 | + * @param string $encrypted_text the text to be decrypted |
|
304 | + * @return string |
|
305 | + */ |
|
306 | + private function acme_decrypt($encrypted_text = '') |
|
307 | + { |
|
308 | + // you give me nothing??? GET OUT ! |
|
309 | + if (empty($encrypted_text)) { |
|
310 | + return $encrypted_text; |
|
311 | + } |
|
312 | + // decode the data ? |
|
313 | + $encrypted_text = $this->valid_base_64($encrypted_text) ? base64_decode($encrypted_text) : $encrypted_text; |
|
314 | + $key_bits = str_split(str_pad('', strlen($encrypted_text), $this->get_encryption_key(), STR_PAD_RIGHT)); |
|
315 | + $string_bits = str_split($encrypted_text); |
|
316 | + foreach ($string_bits as $k => $v) { |
|
317 | + $temp = ord($v) - ord($key_bits[$k]); |
|
318 | + $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp); |
|
319 | + } |
|
320 | + return implode('', $string_bits); |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906 |
|
327 | + * @param $string |
|
328 | + * @return bool |
|
329 | + */ |
|
330 | + private function valid_base_64($string) |
|
331 | + { |
|
332 | + // ensure data is a string |
|
333 | + if ( ! is_string($string) || ! function_exists('base64_decode')) { |
|
334 | + return false; |
|
335 | + } |
|
336 | + $decoded = base64_decode($string, true); |
|
337 | + // Check if there is no invalid character in string |
|
338 | + if ( ! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
339 | + return false; |
|
340 | + } |
|
341 | + // Decode the string in strict mode and send the response |
|
342 | + if ( ! base64_decode($string, true)) { |
|
343 | + return false; |
|
344 | + } |
|
345 | + // Encode and compare it to original one |
|
346 | + return base64_encode($decoded) === $string; |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + |
|
351 | + /** |
|
352 | + * generate random string |
|
353 | + * |
|
354 | + * @source : http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php |
|
355 | + * @access public |
|
356 | + * @param int $length |
|
357 | + * @internal param $string - number of characters for random string |
|
358 | + * @return string |
|
359 | + */ |
|
360 | + public function generate_random_string($length = 40) |
|
361 | + { |
|
362 | + $iterations = ceil($length / 40); |
|
363 | + $random_string = ''; |
|
364 | + for ($i = 0; $i < $iterations; $i++) { |
|
365 | + $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
366 | + } |
|
367 | + $random_string = substr($random_string, 0, $length); |
|
368 | + return $random_string; |
|
369 | + } |
|
371 | 370 | |
372 | 371 | |
373 | 372 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -17,407 +17,407 @@ discard block |
||
17 | 17 | class EE_Payment_Method_Manager |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * instance of the EE_Payment_Method_Manager object |
|
22 | - * |
|
23 | - * @var $_instance |
|
24 | - * @access private |
|
25 | - */ |
|
26 | - private static $_instance; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var array keys are classnames without 'EE_PMT_', values are their filepaths |
|
30 | - */ |
|
31 | - protected $_payment_method_types = array(); |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @singleton method used to instantiate class object |
|
37 | - * @access public |
|
38 | - * @return EE_Payment_Method_Manager instance |
|
39 | - */ |
|
40 | - public static function instance() |
|
41 | - { |
|
42 | - // check if class object is instantiated, and instantiated properly |
|
43 | - if ( ! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
44 | - self::$_instance = new self(); |
|
45 | - } |
|
46 | - EE_Registry::instance()->load_lib('PMT_Base'); |
|
47 | - return self::$_instance; |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Resets the instance and returns a new one |
|
54 | - * |
|
55 | - * @return EE_Payment_Method_Manager |
|
56 | - */ |
|
57 | - public static function reset() |
|
58 | - { |
|
59 | - self::$_instance = null; |
|
60 | - return self::instance(); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * If necessary, re-register payment methods |
|
67 | - * |
|
68 | - * @param boolean $force_recheck whether to recheck for payment method types, |
|
69 | - * or just re-use the PMTs we found last time we checked during this request (if |
|
70 | - * we have not yet checked during this request, then we need to check anyways) |
|
71 | - */ |
|
72 | - public function maybe_register_payment_methods($force_recheck = false) |
|
73 | - { |
|
74 | - if ( ! $this->_payment_method_types || $force_recheck) { |
|
75 | - $this->_register_payment_methods(); |
|
76 | - //if in admin lets ensure caps are set. |
|
77 | - if (is_admin()) { |
|
78 | - add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps')); |
|
79 | - EE_Registry::instance()->CAP->init_caps(); |
|
80 | - } |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * register_payment_methods |
|
88 | - * |
|
89 | - * @return array |
|
90 | - */ |
|
91 | - protected function _register_payment_methods() |
|
92 | - { |
|
93 | - // grab list of installed modules |
|
94 | - $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
95 | - // filter list of modules to register |
|
96 | - $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
97 | - $pm_to_register); |
|
98 | - // loop through folders |
|
99 | - foreach ($pm_to_register as $pm_path) { |
|
100 | - $this->register_payment_method($pm_path); |
|
101 | - } |
|
102 | - do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
103 | - // filter list of installed modules |
|
104 | - //keep them organized alphabetically by the payment method type's name |
|
105 | - ksort($this->_payment_method_types); |
|
106 | - return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
107 | - $this->_payment_method_types); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * register_payment_method- makes core aware of this payment method |
|
114 | - * |
|
115 | - * @access public |
|
116 | - * @param string $payment_method_path - full path up to and including payment method folder |
|
117 | - * @return boolean |
|
118 | - */ |
|
119 | - public function register_payment_method($payment_method_path = '') |
|
120 | - { |
|
121 | - do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
122 | - $module_ext = '.pm.php'; |
|
123 | - // make all separators match |
|
124 | - $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
125 | - // grab and sanitize module name |
|
126 | - $module_dir = basename($payment_method_path); |
|
127 | - // create classname from module directory name |
|
128 | - $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir)); |
|
129 | - // add class prefix |
|
130 | - $module_class = 'EE_PMT_' . $module; |
|
131 | - // does the module exist ? |
|
132 | - if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
133 | - $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
134 | - 'event_espresso'), $module); |
|
135 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
136 | - return false; |
|
137 | - } |
|
138 | - if (WP_DEBUG === true) { |
|
139 | - EEH_Debug_Tools::instance()->start_timer(); |
|
140 | - } |
|
141 | - // load the module class file |
|
142 | - require_once($payment_method_path . DS . $module_class . $module_ext); |
|
143 | - if (WP_DEBUG === true) { |
|
144 | - EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); |
|
145 | - } |
|
146 | - // verify that class exists |
|
147 | - if ( ! class_exists($module_class)) { |
|
148 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
149 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
150 | - return false; |
|
151 | - } |
|
152 | - // add to array of registered modules |
|
153 | - $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
154 | - return true; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * Checks if a payment method has been registered, and if so includes it |
|
161 | - * |
|
162 | - * @param string $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_') |
|
163 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
164 | - * @return boolean |
|
165 | - */ |
|
166 | - public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
167 | - { |
|
168 | - if ( |
|
169 | - $force_recheck |
|
170 | - || ! is_array($this->_payment_method_types) |
|
171 | - || ! isset($this->_payment_method_types[$payment_method_name]) |
|
172 | - ) { |
|
173 | - $this->maybe_register_payment_methods($force_recheck); |
|
174 | - } |
|
175 | - if (isset($this->_payment_method_types[$payment_method_name])) { |
|
176 | - require_once($this->_payment_method_types[$payment_method_name]); |
|
177 | - return true; |
|
178 | - } else { |
|
179 | - return false; |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Returns all the classnames of the various payment method types |
|
187 | - * |
|
188 | - * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names' |
|
189 | - * (what you'd find in wp_esp_payment_method.PMD_type) |
|
190 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
194 | - { |
|
195 | - $this->maybe_register_payment_methods($force_recheck); |
|
196 | - if ($with_prefixes) { |
|
197 | - $classnames = array_keys($this->_payment_method_types); |
|
198 | - $payment_methods = array(); |
|
199 | - foreach ($classnames as $classname) { |
|
200 | - $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
201 | - } |
|
202 | - return $payment_methods; |
|
203 | - } else { |
|
204 | - return array_keys($this->_payment_method_types); |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Gets an object of each payment method type, none of which are bound to a |
|
212 | - * payment method instance |
|
213 | - * |
|
214 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
215 | - * @return EE_PMT_Base[] |
|
216 | - */ |
|
217 | - public function payment_method_types($force_recheck = false) |
|
218 | - { |
|
219 | - $this->maybe_register_payment_methods($force_recheck); |
|
220 | - $pmt_objs = array(); |
|
221 | - foreach ($this->payment_method_type_names(true) as $classname) { |
|
222 | - $pmt_objs[] = new $classname; |
|
223 | - } |
|
224 | - return $pmt_objs; |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * Changes the payment method's classname into the payment method type's name |
|
231 | - * (as used on the payment method's table's PMD_type field) |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - public function payment_method_type_sans_class_prefix($classname) |
|
237 | - { |
|
238 | - return str_replace("EE_PMT_", "", $classname); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * Does the opposite of payment-method_type_sans_prefix |
|
245 | - * |
|
246 | - * @param string $type |
|
247 | - * @return string |
|
248 | - */ |
|
249 | - public function payment_method_class_from_type($type) |
|
250 | - { |
|
251 | - $this->maybe_register_payment_methods(); |
|
252 | - return "EE_PMT_" . $type; |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * Activates a payment method of the given type. |
|
259 | - * |
|
260 | - * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
261 | - * @return \EE_Payment_Method |
|
262 | - * @throws \EE_Error |
|
263 | - */ |
|
264 | - public function activate_a_payment_method_of_type($payment_method_type) |
|
265 | - { |
|
266 | - $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
267 | - if ( ! $payment_method instanceof EE_Payment_Method) { |
|
268 | - $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
269 | - if (class_exists($pm_type_class)) { |
|
270 | - /** @var $pm_type_obj EE_PMT_Base */ |
|
271 | - $pm_type_obj = new $pm_type_class; |
|
272 | - $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
273 | - if ( ! $payment_method) { |
|
274 | - $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
275 | - } |
|
276 | - $payment_method->set_type($payment_method_type); |
|
277 | - $this->initialize_payment_method($payment_method); |
|
278 | - } else { |
|
279 | - throw new EE_Error( |
|
280 | - sprintf( |
|
281 | - __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'), |
|
282 | - $pm_type_class) |
|
283 | - ); |
|
284 | - } |
|
285 | - } |
|
286 | - $payment_method->set_active(); |
|
287 | - $payment_method->save(); |
|
288 | - $this->set_usable_currencies_on_payment_method($payment_method); |
|
289 | - if ($payment_method->type() === 'Invoice') { |
|
290 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
291 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
292 | - $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
293 | - $message_resource_manager->ensure_messenger_is_active('pdf'); |
|
294 | - EE_Error::add_persistent_admin_notice( |
|
295 | - 'invoice_pm_requirements_notice', |
|
296 | - sprintf( |
|
297 | - __('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.', |
|
298 | - 'event_espresso'), |
|
299 | - '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
300 | - '</a>' |
|
301 | - ), |
|
302 | - true |
|
303 | - ); |
|
304 | - } |
|
305 | - return $payment_method; |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * Creates a payment method of the specified type. Does not save it. |
|
312 | - * |
|
313 | - * @global WP_User $current_user |
|
314 | - * @param EE_PMT_Base $pm_type_obj |
|
315 | - * @return EE_Payment_Method |
|
316 | - * @throws \EE_Error |
|
317 | - */ |
|
318 | - public function create_payment_method_of_type($pm_type_obj) |
|
319 | - { |
|
320 | - global $current_user; |
|
321 | - $payment_method = EE_Payment_Method::new_instance( |
|
322 | - array( |
|
323 | - 'PMD_type' => $pm_type_obj->system_name(), |
|
324 | - 'PMD_name' => $pm_type_obj->pretty_name(), |
|
325 | - 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
326 | - 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
327 | - 'PMD_wp_user' => $current_user->ID, |
|
328 | - 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
329 | - array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
330 | - ) * 10, |
|
331 | - ) |
|
332 | - ); |
|
333 | - return $payment_method; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * Sets the initial payment method properties (including extra meta) |
|
340 | - * |
|
341 | - * @param EE_Payment_Method $payment_method |
|
342 | - * @return EE_Payment_Method |
|
343 | - * @throws \EE_Error |
|
344 | - */ |
|
345 | - public function initialize_payment_method($payment_method) |
|
346 | - { |
|
347 | - $pm_type_obj = $payment_method->type_obj(); |
|
348 | - $payment_method->set_description($pm_type_obj->default_description()); |
|
349 | - if ( ! $payment_method->button_url()) { |
|
350 | - $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
351 | - } |
|
352 | - //now add setup its default extra meta properties |
|
353 | - $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
354 | - if ( ! empty($extra_metas)) { |
|
355 | - //verify the payment method has an ID before adding extra meta |
|
356 | - if ( ! $payment_method->ID()) { |
|
357 | - $payment_method->save(); |
|
358 | - } |
|
359 | - foreach ($extra_metas as $meta_name => $input) { |
|
360 | - $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
361 | - } |
|
362 | - } |
|
363 | - return $payment_method; |
|
364 | - } |
|
365 | - |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * Makes sure the payment method is related to the specified payment method |
|
370 | - * |
|
371 | - * @param EE_Payment_Method $payment_method |
|
372 | - * @return EE_Payment_Method |
|
373 | - * @throws \EE_Error |
|
374 | - */ |
|
375 | - public function set_usable_currencies_on_payment_method($payment_method) |
|
376 | - { |
|
377 | - foreach ($payment_method->get_all_usable_currencies() as $currency_obj) { |
|
378 | - $payment_method->_add_relation_to($currency_obj, 'Currency'); |
|
379 | - } |
|
380 | - return $payment_method; |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * Deactivates a payment method of the given payment method slug. |
|
387 | - * |
|
388 | - * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
389 | - * @return int count of rows updated. |
|
390 | - */ |
|
391 | - public function deactivate_payment_method($payment_method_slug) |
|
392 | - { |
|
393 | - EE_Log::instance()->log( |
|
394 | - __FILE__, |
|
395 | - __FUNCTION__, |
|
396 | - sprintf( |
|
397 | - __('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'), |
|
398 | - $payment_method_slug |
|
399 | - ), |
|
400 | - 'payment_method_change' |
|
401 | - ); |
|
402 | - $count_updated = EEM_Payment_Method::instance()->update( |
|
403 | - array('PMD_scope' => array()), |
|
404 | - array(array('PMD_slug' => $payment_method_slug)) |
|
405 | - ); |
|
406 | - return $count_updated; |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method |
|
413 | - * access caps. |
|
414 | - * |
|
415 | - * @param array $caps capabilities being filtered |
|
416 | - * @return array |
|
417 | - */ |
|
418 | - public function add_payment_method_caps($caps) |
|
419 | - { |
|
420 | - /* add dynamic caps from payment methods |
|
20 | + /** |
|
21 | + * instance of the EE_Payment_Method_Manager object |
|
22 | + * |
|
23 | + * @var $_instance |
|
24 | + * @access private |
|
25 | + */ |
|
26 | + private static $_instance; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var array keys are classnames without 'EE_PMT_', values are their filepaths |
|
30 | + */ |
|
31 | + protected $_payment_method_types = array(); |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @singleton method used to instantiate class object |
|
37 | + * @access public |
|
38 | + * @return EE_Payment_Method_Manager instance |
|
39 | + */ |
|
40 | + public static function instance() |
|
41 | + { |
|
42 | + // check if class object is instantiated, and instantiated properly |
|
43 | + if ( ! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
44 | + self::$_instance = new self(); |
|
45 | + } |
|
46 | + EE_Registry::instance()->load_lib('PMT_Base'); |
|
47 | + return self::$_instance; |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Resets the instance and returns a new one |
|
54 | + * |
|
55 | + * @return EE_Payment_Method_Manager |
|
56 | + */ |
|
57 | + public static function reset() |
|
58 | + { |
|
59 | + self::$_instance = null; |
|
60 | + return self::instance(); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * If necessary, re-register payment methods |
|
67 | + * |
|
68 | + * @param boolean $force_recheck whether to recheck for payment method types, |
|
69 | + * or just re-use the PMTs we found last time we checked during this request (if |
|
70 | + * we have not yet checked during this request, then we need to check anyways) |
|
71 | + */ |
|
72 | + public function maybe_register_payment_methods($force_recheck = false) |
|
73 | + { |
|
74 | + if ( ! $this->_payment_method_types || $force_recheck) { |
|
75 | + $this->_register_payment_methods(); |
|
76 | + //if in admin lets ensure caps are set. |
|
77 | + if (is_admin()) { |
|
78 | + add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps')); |
|
79 | + EE_Registry::instance()->CAP->init_caps(); |
|
80 | + } |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * register_payment_methods |
|
88 | + * |
|
89 | + * @return array |
|
90 | + */ |
|
91 | + protected function _register_payment_methods() |
|
92 | + { |
|
93 | + // grab list of installed modules |
|
94 | + $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
95 | + // filter list of modules to register |
|
96 | + $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
97 | + $pm_to_register); |
|
98 | + // loop through folders |
|
99 | + foreach ($pm_to_register as $pm_path) { |
|
100 | + $this->register_payment_method($pm_path); |
|
101 | + } |
|
102 | + do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
103 | + // filter list of installed modules |
|
104 | + //keep them organized alphabetically by the payment method type's name |
|
105 | + ksort($this->_payment_method_types); |
|
106 | + return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
107 | + $this->_payment_method_types); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * register_payment_method- makes core aware of this payment method |
|
114 | + * |
|
115 | + * @access public |
|
116 | + * @param string $payment_method_path - full path up to and including payment method folder |
|
117 | + * @return boolean |
|
118 | + */ |
|
119 | + public function register_payment_method($payment_method_path = '') |
|
120 | + { |
|
121 | + do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
122 | + $module_ext = '.pm.php'; |
|
123 | + // make all separators match |
|
124 | + $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
125 | + // grab and sanitize module name |
|
126 | + $module_dir = basename($payment_method_path); |
|
127 | + // create classname from module directory name |
|
128 | + $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir)); |
|
129 | + // add class prefix |
|
130 | + $module_class = 'EE_PMT_' . $module; |
|
131 | + // does the module exist ? |
|
132 | + if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
133 | + $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
134 | + 'event_espresso'), $module); |
|
135 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
136 | + return false; |
|
137 | + } |
|
138 | + if (WP_DEBUG === true) { |
|
139 | + EEH_Debug_Tools::instance()->start_timer(); |
|
140 | + } |
|
141 | + // load the module class file |
|
142 | + require_once($payment_method_path . DS . $module_class . $module_ext); |
|
143 | + if (WP_DEBUG === true) { |
|
144 | + EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); |
|
145 | + } |
|
146 | + // verify that class exists |
|
147 | + if ( ! class_exists($module_class)) { |
|
148 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
149 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
150 | + return false; |
|
151 | + } |
|
152 | + // add to array of registered modules |
|
153 | + $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
154 | + return true; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * Checks if a payment method has been registered, and if so includes it |
|
161 | + * |
|
162 | + * @param string $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_') |
|
163 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
164 | + * @return boolean |
|
165 | + */ |
|
166 | + public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
167 | + { |
|
168 | + if ( |
|
169 | + $force_recheck |
|
170 | + || ! is_array($this->_payment_method_types) |
|
171 | + || ! isset($this->_payment_method_types[$payment_method_name]) |
|
172 | + ) { |
|
173 | + $this->maybe_register_payment_methods($force_recheck); |
|
174 | + } |
|
175 | + if (isset($this->_payment_method_types[$payment_method_name])) { |
|
176 | + require_once($this->_payment_method_types[$payment_method_name]); |
|
177 | + return true; |
|
178 | + } else { |
|
179 | + return false; |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Returns all the classnames of the various payment method types |
|
187 | + * |
|
188 | + * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names' |
|
189 | + * (what you'd find in wp_esp_payment_method.PMD_type) |
|
190 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
194 | + { |
|
195 | + $this->maybe_register_payment_methods($force_recheck); |
|
196 | + if ($with_prefixes) { |
|
197 | + $classnames = array_keys($this->_payment_method_types); |
|
198 | + $payment_methods = array(); |
|
199 | + foreach ($classnames as $classname) { |
|
200 | + $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
201 | + } |
|
202 | + return $payment_methods; |
|
203 | + } else { |
|
204 | + return array_keys($this->_payment_method_types); |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Gets an object of each payment method type, none of which are bound to a |
|
212 | + * payment method instance |
|
213 | + * |
|
214 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
215 | + * @return EE_PMT_Base[] |
|
216 | + */ |
|
217 | + public function payment_method_types($force_recheck = false) |
|
218 | + { |
|
219 | + $this->maybe_register_payment_methods($force_recheck); |
|
220 | + $pmt_objs = array(); |
|
221 | + foreach ($this->payment_method_type_names(true) as $classname) { |
|
222 | + $pmt_objs[] = new $classname; |
|
223 | + } |
|
224 | + return $pmt_objs; |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * Changes the payment method's classname into the payment method type's name |
|
231 | + * (as used on the payment method's table's PMD_type field) |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + public function payment_method_type_sans_class_prefix($classname) |
|
237 | + { |
|
238 | + return str_replace("EE_PMT_", "", $classname); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * Does the opposite of payment-method_type_sans_prefix |
|
245 | + * |
|
246 | + * @param string $type |
|
247 | + * @return string |
|
248 | + */ |
|
249 | + public function payment_method_class_from_type($type) |
|
250 | + { |
|
251 | + $this->maybe_register_payment_methods(); |
|
252 | + return "EE_PMT_" . $type; |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * Activates a payment method of the given type. |
|
259 | + * |
|
260 | + * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
261 | + * @return \EE_Payment_Method |
|
262 | + * @throws \EE_Error |
|
263 | + */ |
|
264 | + public function activate_a_payment_method_of_type($payment_method_type) |
|
265 | + { |
|
266 | + $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
267 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
268 | + $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
269 | + if (class_exists($pm_type_class)) { |
|
270 | + /** @var $pm_type_obj EE_PMT_Base */ |
|
271 | + $pm_type_obj = new $pm_type_class; |
|
272 | + $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
273 | + if ( ! $payment_method) { |
|
274 | + $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
275 | + } |
|
276 | + $payment_method->set_type($payment_method_type); |
|
277 | + $this->initialize_payment_method($payment_method); |
|
278 | + } else { |
|
279 | + throw new EE_Error( |
|
280 | + sprintf( |
|
281 | + __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'), |
|
282 | + $pm_type_class) |
|
283 | + ); |
|
284 | + } |
|
285 | + } |
|
286 | + $payment_method->set_active(); |
|
287 | + $payment_method->save(); |
|
288 | + $this->set_usable_currencies_on_payment_method($payment_method); |
|
289 | + if ($payment_method->type() === 'Invoice') { |
|
290 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
291 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
292 | + $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
293 | + $message_resource_manager->ensure_messenger_is_active('pdf'); |
|
294 | + EE_Error::add_persistent_admin_notice( |
|
295 | + 'invoice_pm_requirements_notice', |
|
296 | + sprintf( |
|
297 | + __('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.', |
|
298 | + 'event_espresso'), |
|
299 | + '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
300 | + '</a>' |
|
301 | + ), |
|
302 | + true |
|
303 | + ); |
|
304 | + } |
|
305 | + return $payment_method; |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * Creates a payment method of the specified type. Does not save it. |
|
312 | + * |
|
313 | + * @global WP_User $current_user |
|
314 | + * @param EE_PMT_Base $pm_type_obj |
|
315 | + * @return EE_Payment_Method |
|
316 | + * @throws \EE_Error |
|
317 | + */ |
|
318 | + public function create_payment_method_of_type($pm_type_obj) |
|
319 | + { |
|
320 | + global $current_user; |
|
321 | + $payment_method = EE_Payment_Method::new_instance( |
|
322 | + array( |
|
323 | + 'PMD_type' => $pm_type_obj->system_name(), |
|
324 | + 'PMD_name' => $pm_type_obj->pretty_name(), |
|
325 | + 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
326 | + 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
327 | + 'PMD_wp_user' => $current_user->ID, |
|
328 | + 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
329 | + array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
330 | + ) * 10, |
|
331 | + ) |
|
332 | + ); |
|
333 | + return $payment_method; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * Sets the initial payment method properties (including extra meta) |
|
340 | + * |
|
341 | + * @param EE_Payment_Method $payment_method |
|
342 | + * @return EE_Payment_Method |
|
343 | + * @throws \EE_Error |
|
344 | + */ |
|
345 | + public function initialize_payment_method($payment_method) |
|
346 | + { |
|
347 | + $pm_type_obj = $payment_method->type_obj(); |
|
348 | + $payment_method->set_description($pm_type_obj->default_description()); |
|
349 | + if ( ! $payment_method->button_url()) { |
|
350 | + $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
351 | + } |
|
352 | + //now add setup its default extra meta properties |
|
353 | + $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
354 | + if ( ! empty($extra_metas)) { |
|
355 | + //verify the payment method has an ID before adding extra meta |
|
356 | + if ( ! $payment_method->ID()) { |
|
357 | + $payment_method->save(); |
|
358 | + } |
|
359 | + foreach ($extra_metas as $meta_name => $input) { |
|
360 | + $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
361 | + } |
|
362 | + } |
|
363 | + return $payment_method; |
|
364 | + } |
|
365 | + |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * Makes sure the payment method is related to the specified payment method |
|
370 | + * |
|
371 | + * @param EE_Payment_Method $payment_method |
|
372 | + * @return EE_Payment_Method |
|
373 | + * @throws \EE_Error |
|
374 | + */ |
|
375 | + public function set_usable_currencies_on_payment_method($payment_method) |
|
376 | + { |
|
377 | + foreach ($payment_method->get_all_usable_currencies() as $currency_obj) { |
|
378 | + $payment_method->_add_relation_to($currency_obj, 'Currency'); |
|
379 | + } |
|
380 | + return $payment_method; |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * Deactivates a payment method of the given payment method slug. |
|
387 | + * |
|
388 | + * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
389 | + * @return int count of rows updated. |
|
390 | + */ |
|
391 | + public function deactivate_payment_method($payment_method_slug) |
|
392 | + { |
|
393 | + EE_Log::instance()->log( |
|
394 | + __FILE__, |
|
395 | + __FUNCTION__, |
|
396 | + sprintf( |
|
397 | + __('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'), |
|
398 | + $payment_method_slug |
|
399 | + ), |
|
400 | + 'payment_method_change' |
|
401 | + ); |
|
402 | + $count_updated = EEM_Payment_Method::instance()->update( |
|
403 | + array('PMD_scope' => array()), |
|
404 | + array(array('PMD_slug' => $payment_method_slug)) |
|
405 | + ); |
|
406 | + return $count_updated; |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method |
|
413 | + * access caps. |
|
414 | + * |
|
415 | + * @param array $caps capabilities being filtered |
|
416 | + * @return array |
|
417 | + */ |
|
418 | + public function add_payment_method_caps($caps) |
|
419 | + { |
|
420 | + /* add dynamic caps from payment methods |
|
421 | 421 | * at the time of writing, october 20 2014, these are the caps added: |
422 | 422 | * ee_payment_method_admin_only |
423 | 423 | * ee_payment_method_aim |
@@ -431,10 +431,10 @@ discard block |
||
431 | 431 | * their related capability automatically added too, so long as they are |
432 | 432 | * registered properly using EE_Register_Payment_Method::register() |
433 | 433 | */ |
434 | - foreach ($this->payment_method_types() as $payment_method_type_obj) { |
|
435 | - $caps['administrator'][] = $payment_method_type_obj->cap_name(); |
|
436 | - } |
|
437 | - return $caps; |
|
438 | - } |
|
434 | + foreach ($this->payment_method_types() as $payment_method_type_obj) { |
|
435 | + $caps['administrator'][] = $payment_method_type_obj->cap_name(); |
|
436 | + } |
|
437 | + return $caps; |
|
438 | + } |
|
439 | 439 | |
440 | 440 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | protected function _register_payment_methods() |
92 | 92 | { |
93 | 93 | // grab list of installed modules |
94 | - $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
94 | + $pm_to_register = glob(EE_PAYMENT_METHODS.'*', GLOB_ONLYDIR); |
|
95 | 95 | // filter list of modules to register |
96 | 96 | $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
97 | 97 | $pm_to_register); |
@@ -127,30 +127,30 @@ discard block |
||
127 | 127 | // create classname from module directory name |
128 | 128 | $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir)); |
129 | 129 | // add class prefix |
130 | - $module_class = 'EE_PMT_' . $module; |
|
130 | + $module_class = 'EE_PMT_'.$module; |
|
131 | 131 | // does the module exist ? |
132 | - if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
132 | + if ( ! is_readable($payment_method_path.DS.$module_class.$module_ext)) { |
|
133 | 133 | $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', |
134 | 134 | 'event_espresso'), $module); |
135 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
135 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
136 | 136 | return false; |
137 | 137 | } |
138 | 138 | if (WP_DEBUG === true) { |
139 | 139 | EEH_Debug_Tools::instance()->start_timer(); |
140 | 140 | } |
141 | 141 | // load the module class file |
142 | - require_once($payment_method_path . DS . $module_class . $module_ext); |
|
142 | + require_once($payment_method_path.DS.$module_class.$module_ext); |
|
143 | 143 | if (WP_DEBUG === true) { |
144 | 144 | EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); |
145 | 145 | } |
146 | 146 | // verify that class exists |
147 | 147 | if ( ! class_exists($module_class)) { |
148 | 148 | $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
149 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
149 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
150 | 150 | return false; |
151 | 151 | } |
152 | 152 | // add to array of registered modules |
153 | - $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
153 | + $this->_payment_method_types[$module] = $payment_method_path.DS.$module_class.$module_ext; |
|
154 | 154 | return true; |
155 | 155 | } |
156 | 156 | |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | public function payment_method_class_from_type($type) |
250 | 250 | { |
251 | 251 | $this->maybe_register_payment_methods(); |
252 | - return "EE_PMT_" . $type; |
|
252 | + return "EE_PMT_".$type; |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | sprintf( |
297 | 297 | __('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.', |
298 | 298 | 'event_espresso'), |
299 | - '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
299 | + '<a href="'.admin_url('admin.php?page=espresso_messages').'">', |
|
300 | 300 | '</a>' |
301 | 301 | ), |
302 | 302 | true |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | 'PMD_type' => $pm_type_obj->system_name(), |
324 | 324 | 'PMD_name' => $pm_type_obj->pretty_name(), |
325 | 325 | 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
326 | - 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
326 | + 'PMD_slug' => $pm_type_obj->system_name(), //automatically converted to slug |
|
327 | 327 | 'PMD_wp_user' => $current_user->ID, |
328 | 328 | 'PMD_order' => EEM_Payment_Method::instance()->count( |
329 | 329 | array(array('PMD_type' => array('!=', 'Admin_Only'))) |