@@ -18,226 +18,226 @@ |
||
18 | 18 | class EE_Registration_CheckIn_List_Table extends EE_Admin_List_Table |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * EE_Registration_CheckIn_List_Table constructor. |
|
23 | - * |
|
24 | - * @param EE_Admin_Page $admin_page |
|
25 | - */ |
|
26 | - public function __construct($admin_page) |
|
27 | - { |
|
28 | - parent::__construct($admin_page); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @throws EE_Error |
|
34 | - */ |
|
35 | - protected function _setup_data() |
|
36 | - { |
|
37 | - $this->_data = $this->_get_checkins($this->_per_page); |
|
38 | - $this->_all_data_count = $this->_get_checkins($this->_per_page, true); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * Sets up the properties for the list table. |
|
44 | - */ |
|
45 | - protected function _set_properties() |
|
46 | - { |
|
47 | - $this->_wp_list_args = array( |
|
48 | - 'singular' => __('check-in', 'event_espresso'), |
|
49 | - 'plural' => __('check-ins', 'event_espresso'), |
|
50 | - 'ajax' => true, |
|
51 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
52 | - ); |
|
53 | - |
|
54 | - $this->_columns = array( |
|
55 | - 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
56 | - 'CHK_in' => __('Check-In', 'event_espresso'), |
|
57 | - 'CHK_timestamp' => __('Timestamp', 'event_espresso'), |
|
58 | - ); |
|
59 | - |
|
60 | - $this->_sortable_columns = array( |
|
61 | - 'CHK_timestamp' => array('CHK_timestamp' => true), |
|
62 | - ); |
|
63 | - |
|
64 | - $this->_primary_column = 'CHK_in'; |
|
65 | - |
|
66 | - $this->_hidden_columns = array(); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @return array |
|
72 | - */ |
|
73 | - protected function _get_table_filters() |
|
74 | - { |
|
75 | - return []; |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Returning an empty string to remove the search box for this view. |
|
81 | - * |
|
82 | - * @param string $text |
|
83 | - * @param string $input_id |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public function search_box($text, $input_id) |
|
87 | - { |
|
88 | - return ''; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @throws EE_Error |
|
94 | - */ |
|
95 | - protected function _add_view_counts() |
|
96 | - { |
|
97 | - $this->_views['all']['count'] = $this->_get_checkins(null, true); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @param EE_Checkin $item |
|
103 | - * @return string |
|
104 | - * @throws EE_Error |
|
105 | - * @throws InvalidArgumentException |
|
106 | - * @throws ReflectionException |
|
107 | - * @throws InvalidDataTypeException |
|
108 | - * @throws InvalidInterfaceException |
|
109 | - */ |
|
110 | - public function column_cb($item) |
|
111 | - { |
|
112 | - return sprintf('<input type="checkbox" name="checkbox[%1$s]" />', $item->ID()); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @param EE_Checkin $item |
|
118 | - * @return string |
|
119 | - * @throws EE_Error |
|
120 | - * @throws InvalidArgumentException |
|
121 | - * @throws InvalidDataTypeException |
|
122 | - * @throws InvalidInterfaceException |
|
123 | - * @throws ReflectionException |
|
124 | - */ |
|
125 | - public function column_CHK_in(EE_Checkin $item) |
|
126 | - { |
|
127 | - $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item); |
|
128 | - return '<span class="' |
|
129 | - . $checkin_status_dashicon->cssClasses() |
|
130 | - . '"></span><span class="show-on-mobile-view-only">' |
|
131 | - . $item->get_datetime('CHK_timestamp') |
|
132 | - . '</span>'; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @param EE_Checkin $item |
|
138 | - * @return string |
|
139 | - * @throws EE_Error |
|
140 | - * @throws InvalidArgumentException |
|
141 | - * @throws InvalidDataTypeException |
|
142 | - * @throws InvalidInterfaceException |
|
143 | - * @throws ReflectionException |
|
144 | - */ |
|
145 | - public function column_CHK_timestamp(EE_Checkin $item) |
|
146 | - { |
|
147 | - $actions = array(); |
|
148 | - $delete_url = EE_Admin_Page::add_query_args_and_nonce( |
|
149 | - array( |
|
150 | - 'action' => 'delete_checkin_row', |
|
151 | - 'DTT_ID' => $this->_req_data['DTT_ID'], |
|
152 | - '_REG_ID' => $this->_req_data['_REG_ID'], |
|
153 | - 'CHK_ID' => $item->ID(), |
|
154 | - ) |
|
155 | - ); |
|
156 | - $actions['delete_checkin'] = EE_Registry::instance()->CAP->current_user_can( |
|
157 | - 'ee_delete_checkins', |
|
158 | - 'espresso_registrations_delete_checkin_row' |
|
159 | - ) |
|
160 | - ? '<a href="' . $delete_url . '" title="' |
|
161 | - . esc_attr__('Click here to delete this check-in record', 'event_espresso') . '">' |
|
162 | - . __('Delete', 'event_espresso') . '</a>' |
|
163 | - : ''; |
|
164 | - |
|
165 | - return sprintf( |
|
166 | - '%1$s %2$s', |
|
167 | - $item->get_datetime('CHK_timestamp', '', 'H:i:s a'), |
|
168 | - $this->row_actions($actions) |
|
169 | - ); |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * This retrieves all the Check-ins for the given parameters. |
|
175 | - * experimenting with having the query for the table values within the list table. |
|
176 | - * |
|
177 | - * @param int $per_page How many to retrieve per page |
|
178 | - * @param bool $count Whether to return a count or not |
|
179 | - * @return EE_Checkin[]|int |
|
180 | - * @throws EE_Error |
|
181 | - * @throws InvalidArgumentException |
|
182 | - * @throws InvalidDataTypeException |
|
183 | - * @throws InvalidInterfaceException |
|
184 | - */ |
|
185 | - protected function _get_checkins($per_page = 10, $count = false) |
|
186 | - { |
|
187 | - $REG_ID = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : false; |
|
188 | - $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : false; |
|
189 | - |
|
190 | - // if user does not have the capability for the checkins for this registration then get out! |
|
191 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
192 | - 'ee_read_checkin', |
|
193 | - 'espresso_registrations_registration_checkins', |
|
194 | - $REG_ID |
|
195 | - )) { |
|
196 | - return $count ? 0 : array(); |
|
197 | - } |
|
198 | - |
|
199 | - // if no reg id then get out cause need a reg id |
|
200 | - if (empty($REG_ID) || empty($DTT_ID)) { |
|
201 | - throw new EE_Error( |
|
202 | - __( |
|
203 | - 'This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', |
|
204 | - 'event_espresso' |
|
205 | - ) |
|
206 | - ); |
|
207 | - } |
|
208 | - |
|
209 | - // set orderby |
|
210 | - // note that with this table we're only providing the option to orderby the timestamp value. |
|
211 | - $orderby = 'CHK_timestamp'; |
|
212 | - |
|
213 | - $order = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
214 | - |
|
215 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
216 | - ? $this->_req_data['paged'] |
|
217 | - : 1; |
|
218 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
219 | - ? $this->_req_data['perpage'] |
|
220 | - : $per_page; |
|
221 | - $limit = null; |
|
222 | - if (! $count) { |
|
223 | - $offset = ($current_page - 1) * $per_page; |
|
224 | - $limit = array($offset, $per_page); |
|
225 | - } |
|
226 | - |
|
227 | - $_where = array( |
|
228 | - 'REG_ID' => $REG_ID, |
|
229 | - 'DTT_ID' => $DTT_ID, |
|
230 | - ); |
|
231 | - |
|
232 | - $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
233 | - |
|
234 | - // if no per_page value then we just want to return a count of all Check-ins |
|
235 | - if ($count) { |
|
236 | - return EEM_Checkin::instance()->count(array($_where)); |
|
237 | - } |
|
238 | - |
|
239 | - return $count |
|
240 | - ? EEM_Checkin::instance()->count(array($_where)) |
|
241 | - : EEM_Checkin::instance()->get_all($query_params); |
|
242 | - } |
|
21 | + /** |
|
22 | + * EE_Registration_CheckIn_List_Table constructor. |
|
23 | + * |
|
24 | + * @param EE_Admin_Page $admin_page |
|
25 | + */ |
|
26 | + public function __construct($admin_page) |
|
27 | + { |
|
28 | + parent::__construct($admin_page); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @throws EE_Error |
|
34 | + */ |
|
35 | + protected function _setup_data() |
|
36 | + { |
|
37 | + $this->_data = $this->_get_checkins($this->_per_page); |
|
38 | + $this->_all_data_count = $this->_get_checkins($this->_per_page, true); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * Sets up the properties for the list table. |
|
44 | + */ |
|
45 | + protected function _set_properties() |
|
46 | + { |
|
47 | + $this->_wp_list_args = array( |
|
48 | + 'singular' => __('check-in', 'event_espresso'), |
|
49 | + 'plural' => __('check-ins', 'event_espresso'), |
|
50 | + 'ajax' => true, |
|
51 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
52 | + ); |
|
53 | + |
|
54 | + $this->_columns = array( |
|
55 | + 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
56 | + 'CHK_in' => __('Check-In', 'event_espresso'), |
|
57 | + 'CHK_timestamp' => __('Timestamp', 'event_espresso'), |
|
58 | + ); |
|
59 | + |
|
60 | + $this->_sortable_columns = array( |
|
61 | + 'CHK_timestamp' => array('CHK_timestamp' => true), |
|
62 | + ); |
|
63 | + |
|
64 | + $this->_primary_column = 'CHK_in'; |
|
65 | + |
|
66 | + $this->_hidden_columns = array(); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @return array |
|
72 | + */ |
|
73 | + protected function _get_table_filters() |
|
74 | + { |
|
75 | + return []; |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Returning an empty string to remove the search box for this view. |
|
81 | + * |
|
82 | + * @param string $text |
|
83 | + * @param string $input_id |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public function search_box($text, $input_id) |
|
87 | + { |
|
88 | + return ''; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @throws EE_Error |
|
94 | + */ |
|
95 | + protected function _add_view_counts() |
|
96 | + { |
|
97 | + $this->_views['all']['count'] = $this->_get_checkins(null, true); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @param EE_Checkin $item |
|
103 | + * @return string |
|
104 | + * @throws EE_Error |
|
105 | + * @throws InvalidArgumentException |
|
106 | + * @throws ReflectionException |
|
107 | + * @throws InvalidDataTypeException |
|
108 | + * @throws InvalidInterfaceException |
|
109 | + */ |
|
110 | + public function column_cb($item) |
|
111 | + { |
|
112 | + return sprintf('<input type="checkbox" name="checkbox[%1$s]" />', $item->ID()); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @param EE_Checkin $item |
|
118 | + * @return string |
|
119 | + * @throws EE_Error |
|
120 | + * @throws InvalidArgumentException |
|
121 | + * @throws InvalidDataTypeException |
|
122 | + * @throws InvalidInterfaceException |
|
123 | + * @throws ReflectionException |
|
124 | + */ |
|
125 | + public function column_CHK_in(EE_Checkin $item) |
|
126 | + { |
|
127 | + $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item); |
|
128 | + return '<span class="' |
|
129 | + . $checkin_status_dashicon->cssClasses() |
|
130 | + . '"></span><span class="show-on-mobile-view-only">' |
|
131 | + . $item->get_datetime('CHK_timestamp') |
|
132 | + . '</span>'; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @param EE_Checkin $item |
|
138 | + * @return string |
|
139 | + * @throws EE_Error |
|
140 | + * @throws InvalidArgumentException |
|
141 | + * @throws InvalidDataTypeException |
|
142 | + * @throws InvalidInterfaceException |
|
143 | + * @throws ReflectionException |
|
144 | + */ |
|
145 | + public function column_CHK_timestamp(EE_Checkin $item) |
|
146 | + { |
|
147 | + $actions = array(); |
|
148 | + $delete_url = EE_Admin_Page::add_query_args_and_nonce( |
|
149 | + array( |
|
150 | + 'action' => 'delete_checkin_row', |
|
151 | + 'DTT_ID' => $this->_req_data['DTT_ID'], |
|
152 | + '_REG_ID' => $this->_req_data['_REG_ID'], |
|
153 | + 'CHK_ID' => $item->ID(), |
|
154 | + ) |
|
155 | + ); |
|
156 | + $actions['delete_checkin'] = EE_Registry::instance()->CAP->current_user_can( |
|
157 | + 'ee_delete_checkins', |
|
158 | + 'espresso_registrations_delete_checkin_row' |
|
159 | + ) |
|
160 | + ? '<a href="' . $delete_url . '" title="' |
|
161 | + . esc_attr__('Click here to delete this check-in record', 'event_espresso') . '">' |
|
162 | + . __('Delete', 'event_espresso') . '</a>' |
|
163 | + : ''; |
|
164 | + |
|
165 | + return sprintf( |
|
166 | + '%1$s %2$s', |
|
167 | + $item->get_datetime('CHK_timestamp', '', 'H:i:s a'), |
|
168 | + $this->row_actions($actions) |
|
169 | + ); |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * This retrieves all the Check-ins for the given parameters. |
|
175 | + * experimenting with having the query for the table values within the list table. |
|
176 | + * |
|
177 | + * @param int $per_page How many to retrieve per page |
|
178 | + * @param bool $count Whether to return a count or not |
|
179 | + * @return EE_Checkin[]|int |
|
180 | + * @throws EE_Error |
|
181 | + * @throws InvalidArgumentException |
|
182 | + * @throws InvalidDataTypeException |
|
183 | + * @throws InvalidInterfaceException |
|
184 | + */ |
|
185 | + protected function _get_checkins($per_page = 10, $count = false) |
|
186 | + { |
|
187 | + $REG_ID = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : false; |
|
188 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : false; |
|
189 | + |
|
190 | + // if user does not have the capability for the checkins for this registration then get out! |
|
191 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
192 | + 'ee_read_checkin', |
|
193 | + 'espresso_registrations_registration_checkins', |
|
194 | + $REG_ID |
|
195 | + )) { |
|
196 | + return $count ? 0 : array(); |
|
197 | + } |
|
198 | + |
|
199 | + // if no reg id then get out cause need a reg id |
|
200 | + if (empty($REG_ID) || empty($DTT_ID)) { |
|
201 | + throw new EE_Error( |
|
202 | + __( |
|
203 | + 'This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', |
|
204 | + 'event_espresso' |
|
205 | + ) |
|
206 | + ); |
|
207 | + } |
|
208 | + |
|
209 | + // set orderby |
|
210 | + // note that with this table we're only providing the option to orderby the timestamp value. |
|
211 | + $orderby = 'CHK_timestamp'; |
|
212 | + |
|
213 | + $order = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
214 | + |
|
215 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
216 | + ? $this->_req_data['paged'] |
|
217 | + : 1; |
|
218 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
219 | + ? $this->_req_data['perpage'] |
|
220 | + : $per_page; |
|
221 | + $limit = null; |
|
222 | + if (! $count) { |
|
223 | + $offset = ($current_page - 1) * $per_page; |
|
224 | + $limit = array($offset, $per_page); |
|
225 | + } |
|
226 | + |
|
227 | + $_where = array( |
|
228 | + 'REG_ID' => $REG_ID, |
|
229 | + 'DTT_ID' => $DTT_ID, |
|
230 | + ); |
|
231 | + |
|
232 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
233 | + |
|
234 | + // if no per_page value then we just want to return a count of all Check-ins |
|
235 | + if ($count) { |
|
236 | + return EEM_Checkin::instance()->count(array($_where)); |
|
237 | + } |
|
238 | + |
|
239 | + return $count |
|
240 | + ? EEM_Checkin::instance()->count(array($_where)) |
|
241 | + : EEM_Checkin::instance()->get_all($query_params); |
|
242 | + } |
|
243 | 243 | } |
@@ -16,145 +16,145 @@ |
||
16 | 16 | interface RequestInterface extends RequestTypeContextCheckerInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @param RequestTypeContextCheckerInterface $type |
|
21 | - */ |
|
22 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
23 | - |
|
24 | - /** |
|
25 | - * @return array |
|
26 | - */ |
|
27 | - public function getParams(); |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @return array |
|
32 | - */ |
|
33 | - public function postParams(); |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - public function cookieParams(); |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * @return array |
|
44 | - */ |
|
45 | - public function serverParams(); |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @return array |
|
50 | - */ |
|
51 | - public function filesParams(); |
|
19 | + /** |
|
20 | + * @param RequestTypeContextCheckerInterface $type |
|
21 | + */ |
|
22 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
23 | + |
|
24 | + /** |
|
25 | + * @return array |
|
26 | + */ |
|
27 | + public function getParams(); |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @return array |
|
32 | + */ |
|
33 | + public function postParams(); |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + public function cookieParams(); |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * @return array |
|
44 | + */ |
|
45 | + public function serverParams(); |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @return array |
|
50 | + */ |
|
51 | + public function filesParams(); |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * returns contents of $_REQUEST |
|
56 | - * |
|
57 | - * @return array |
|
58 | - */ |
|
59 | - public function requestParams(); |
|
54 | + /** |
|
55 | + * returns contents of $_REQUEST |
|
56 | + * |
|
57 | + * @return array |
|
58 | + */ |
|
59 | + public function requestParams(); |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * @param string $key |
|
64 | - * @param string $value |
|
65 | - * @param bool $override_ee |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - public function setRequestParam($key, $value, $override_ee = false); |
|
62 | + /** |
|
63 | + * @param string $key |
|
64 | + * @param string $value |
|
65 | + * @param bool $override_ee |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + public function setRequestParam($key, $value, $override_ee = false); |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * returns the value for a request param if the given key exists |
|
73 | - * |
|
74 | - * @param string $key |
|
75 | - * @param null $default |
|
76 | - * @return mixed |
|
77 | - */ |
|
78 | - public function getRequestParam($key, $default = null); |
|
71 | + /** |
|
72 | + * returns the value for a request param if the given key exists |
|
73 | + * |
|
74 | + * @param string $key |
|
75 | + * @param null $default |
|
76 | + * @return mixed |
|
77 | + */ |
|
78 | + public function getRequestParam($key, $default = null); |
|
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * check if param exists |
|
83 | - * |
|
84 | - * @param string $key |
|
85 | - * @return bool |
|
86 | - */ |
|
87 | - public function requestParamIsSet($key); |
|
81 | + /** |
|
82 | + * check if param exists |
|
83 | + * |
|
84 | + * @param string $key |
|
85 | + * @return bool |
|
86 | + */ |
|
87 | + public function requestParamIsSet($key); |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
92 | - * and return the value for the first match found |
|
93 | - * wildcards can be either of the following: |
|
94 | - * ? to represent a single character of any type |
|
95 | - * * to represent one or more characters of any type |
|
96 | - * |
|
97 | - * @param string $pattern |
|
98 | - * @param null|mixed $default |
|
99 | - * @return false|int |
|
100 | - */ |
|
101 | - public function getMatch($pattern, $default = null); |
|
90 | + /** |
|
91 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
92 | + * and return the value for the first match found |
|
93 | + * wildcards can be either of the following: |
|
94 | + * ? to represent a single character of any type |
|
95 | + * * to represent one or more characters of any type |
|
96 | + * |
|
97 | + * @param string $pattern |
|
98 | + * @param null|mixed $default |
|
99 | + * @return false|int |
|
100 | + */ |
|
101 | + public function getMatch($pattern, $default = null); |
|
102 | 102 | |
103 | 103 | |
104 | - /** |
|
105 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
106 | - * wildcards can be either of the following: |
|
107 | - * ? to represent a single character of any type |
|
108 | - * * to represent one or more characters of any type |
|
109 | - * returns true if a match is found or false if not |
|
110 | - * |
|
111 | - * @param string $pattern |
|
112 | - * @return false|int |
|
113 | - */ |
|
114 | - public function matches($pattern); |
|
104 | + /** |
|
105 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
106 | + * wildcards can be either of the following: |
|
107 | + * ? to represent a single character of any type |
|
108 | + * * to represent one or more characters of any type |
|
109 | + * returns true if a match is found or false if not |
|
110 | + * |
|
111 | + * @param string $pattern |
|
112 | + * @return false|int |
|
113 | + */ |
|
114 | + public function matches($pattern); |
|
115 | 115 | |
116 | 116 | |
117 | - /** |
|
118 | - * remove param |
|
119 | - * |
|
120 | - * @param string $key |
|
121 | - * @param bool $unset_from_global_too |
|
122 | - */ |
|
123 | - public function unSetRequestParam($key, $unset_from_global_too = false); |
|
117 | + /** |
|
118 | + * remove param |
|
119 | + * |
|
120 | + * @param string $key |
|
121 | + * @param bool $unset_from_global_too |
|
122 | + */ |
|
123 | + public function unSetRequestParam($key, $unset_from_global_too = false); |
|
124 | 124 | |
125 | 125 | |
126 | - /** |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public function ipAddress(); |
|
126 | + /** |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public function ipAddress(); |
|
130 | 130 | |
131 | 131 | |
132 | - /** |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - public function requestUri(); |
|
136 | - |
|
132 | + /** |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + public function requestUri(); |
|
136 | + |
|
137 | 137 | |
138 | - /** |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function userAgent(); |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @param string $user_agent |
|
146 | - */ |
|
147 | - public function setUserAgent($user_agent = ''); |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * @return bool |
|
152 | - */ |
|
153 | - public function isBot(); |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * @param bool $is_bot |
|
158 | - */ |
|
159 | - public function setIsBot($is_bot); |
|
138 | + /** |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function userAgent(); |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @param string $user_agent |
|
146 | + */ |
|
147 | + public function setUserAgent($user_agent = ''); |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * @return bool |
|
152 | + */ |
|
153 | + public function isBot(); |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * @param bool $is_bot |
|
158 | + */ |
|
159 | + public function setIsBot($is_bot); |
|
160 | 160 | } |
@@ -17,624 +17,624 @@ |
||
17 | 17 | class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * $_GET parameters |
|
22 | - * |
|
23 | - * @var array $get |
|
24 | - */ |
|
25 | - private $get; |
|
26 | - |
|
27 | - /** |
|
28 | - * $_POST parameters |
|
29 | - * |
|
30 | - * @var array $post |
|
31 | - */ |
|
32 | - private $post; |
|
33 | - |
|
34 | - /** |
|
35 | - * $_COOKIE parameters |
|
36 | - * |
|
37 | - * @var array $cookie |
|
38 | - */ |
|
39 | - private $cookie; |
|
40 | - |
|
41 | - /** |
|
42 | - * $_SERVER parameters |
|
43 | - * |
|
44 | - * @var array $server |
|
45 | - */ |
|
46 | - private $server; |
|
47 | - |
|
48 | - /** |
|
49 | - * $_FILES parameters |
|
50 | - * |
|
51 | - * @var array $files |
|
52 | - */ |
|
53 | - private $files; |
|
54 | - |
|
55 | - /** |
|
56 | - * $_REQUEST parameters |
|
57 | - * |
|
58 | - * @var array $request |
|
59 | - */ |
|
60 | - private $request; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var RequestTypeContextCheckerInterface |
|
64 | - */ |
|
65 | - private $request_type; |
|
66 | - |
|
67 | - /** |
|
68 | - * IP address for request |
|
69 | - * |
|
70 | - * @var string $ip_address |
|
71 | - */ |
|
72 | - private $ip_address; |
|
73 | - |
|
74 | - /** |
|
75 | - * @var string $user_agent |
|
76 | - */ |
|
77 | - private $user_agent; |
|
78 | - |
|
79 | - /** |
|
80 | - * true if current user appears to be some kind of bot |
|
81 | - * |
|
82 | - * @var bool $is_bot |
|
83 | - */ |
|
84 | - private $is_bot; |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @param array $get |
|
89 | - * @param array $post |
|
90 | - * @param array $cookie |
|
91 | - * @param array $server |
|
92 | - * @param array $files |
|
93 | - */ |
|
94 | - public function __construct(array $get, array $post, array $cookie, array $server, array $files = array()) |
|
95 | - { |
|
96 | - // grab request vars |
|
97 | - $this->get = $get; |
|
98 | - $this->post = $post; |
|
99 | - $this->cookie = $cookie; |
|
100 | - $this->server = $server; |
|
101 | - $this->files = $files; |
|
102 | - $this->request = array_merge($this->get, $this->post); |
|
103 | - $this->ip_address = $this->visitorIp(); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @param RequestTypeContextCheckerInterface $type |
|
109 | - */ |
|
110 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
111 | - { |
|
112 | - $this->request_type = $type; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @return array |
|
118 | - */ |
|
119 | - public function getParams() |
|
120 | - { |
|
121 | - return $this->get; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @return array |
|
127 | - */ |
|
128 | - public function postParams() |
|
129 | - { |
|
130 | - return $this->post; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @return array |
|
136 | - */ |
|
137 | - public function cookieParams() |
|
138 | - { |
|
139 | - return $this->cookie; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @return array |
|
145 | - */ |
|
146 | - public function serverParams() |
|
147 | - { |
|
148 | - return $this->server; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - public function filesParams() |
|
156 | - { |
|
157 | - return $this->files; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * returns contents of $_REQUEST |
|
163 | - * |
|
164 | - * @return array |
|
165 | - */ |
|
166 | - public function requestParams() |
|
167 | - { |
|
168 | - return $this->request; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * @param $key |
|
174 | - * @param $value |
|
175 | - * @param bool $override_ee |
|
176 | - * @return void |
|
177 | - */ |
|
178 | - public function setRequestParam($key, $value, $override_ee = false) |
|
179 | - { |
|
180 | - // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
181 | - if ($key !== 'ee' |
|
182 | - || ($key === 'ee' && empty($this->request['ee'])) |
|
183 | - || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
|
184 | - ) { |
|
185 | - $this->request[ $key ] = $value; |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * returns the value for a request param if the given key exists |
|
192 | - * |
|
193 | - * @param $key |
|
194 | - * @param null $default |
|
195 | - * @return mixed |
|
196 | - */ |
|
197 | - public function getRequestParam($key, $default = null) |
|
198 | - { |
|
199 | - return $this->requestParameterDrillDown($key, $default, 'get'); |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * check if param exists |
|
205 | - * |
|
206 | - * @param $key |
|
207 | - * @return bool |
|
208 | - */ |
|
209 | - public function requestParamIsSet($key) |
|
210 | - { |
|
211 | - return $this->requestParameterDrillDown($key); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
217 | - * and return the value for the first match found |
|
218 | - * wildcards can be either of the following: |
|
219 | - * ? to represent a single character of any type |
|
220 | - * * to represent one or more characters of any type |
|
221 | - * |
|
222 | - * @param string $pattern |
|
223 | - * @param null|mixed $default |
|
224 | - * @return mixed |
|
225 | - */ |
|
226 | - public function getMatch($pattern, $default = null) |
|
227 | - { |
|
228 | - return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
234 | - * wildcards can be either of the following: |
|
235 | - * ? to represent a single character of any type |
|
236 | - * * to represent one or more characters of any type |
|
237 | - * returns true if a match is found or false if not |
|
238 | - * |
|
239 | - * @param string $pattern |
|
240 | - * @return bool |
|
241 | - */ |
|
242 | - public function matches($pattern) |
|
243 | - { |
|
244 | - return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
250 | - * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
251 | - * and used to search through the current request's parameter keys |
|
252 | - * @param array $request_params The array of request parameters to search through |
|
253 | - * @param mixed $default [optional] The value to be returned if no match is found. |
|
254 | - * Default is null |
|
255 | - * @param string $return [optional] Controls what kind of value is returned. |
|
256 | - * Options are: |
|
257 | - * 'bool' will return true or false if match is found or not |
|
258 | - * 'key' will return the first key found that matches the supplied pattern |
|
259 | - * 'value' will return the value for the first request parameter |
|
260 | - * whose key matches the supplied pattern |
|
261 | - * Default is 'value' |
|
262 | - * @return boolean|string |
|
263 | - */ |
|
264 | - private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
265 | - { |
|
266 | - $return = in_array($return, array('bool', 'key', 'value'), true) |
|
267 | - ? $return |
|
268 | - : 'is_set'; |
|
269 | - // replace wildcard chars with regex chars |
|
270 | - $pattern = str_replace( |
|
271 | - array("\*", "\?"), |
|
272 | - array('.*', '.'), |
|
273 | - preg_quote($pattern, '/') |
|
274 | - ); |
|
275 | - foreach ($request_params as $key => $request_param) { |
|
276 | - if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
277 | - // return value for request param |
|
278 | - if ($return === 'value') { |
|
279 | - return $request_params[ $key ]; |
|
280 | - } |
|
281 | - // or actual key or true just to indicate it was found |
|
282 | - return $return === 'key' ? $key : true; |
|
283 | - } |
|
284 | - } |
|
285 | - // match not found so return default value or false |
|
286 | - return $return === 'value' ? $default : false; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * the supplied key can be a simple string to represent a "top-level" request parameter |
|
292 | - * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
293 | - * by using square brackets to surround keys for deeper array elements. |
|
294 | - * For example : |
|
295 | - * if the supplied $key was: "first[second][third]" |
|
296 | - * then this will attempt to drill down into the request parameter array to find a value. |
|
297 | - * Given the following request parameters: |
|
298 | - * array( |
|
299 | - * 'first' => array( |
|
300 | - * 'second' => array( |
|
301 | - * 'third' => 'has a value' |
|
302 | - * ) |
|
303 | - * ) |
|
304 | - * ) |
|
305 | - * would return true if default parameters were set |
|
306 | - * |
|
307 | - * @param string $callback |
|
308 | - * @param $key |
|
309 | - * @param null $default |
|
310 | - * @param array $request_params |
|
311 | - * @return bool|mixed|null |
|
312 | - */ |
|
313 | - private function requestParameterDrillDown( |
|
314 | - $key, |
|
315 | - $default = null, |
|
316 | - $callback = 'is_set', |
|
317 | - array $request_params = array() |
|
318 | - ) { |
|
319 | - $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
320 | - ? $callback |
|
321 | - : 'is_set'; |
|
322 | - $request_params = ! empty($request_params) |
|
323 | - ? $request_params |
|
324 | - : $this->request; |
|
325 | - // does incoming key represent an array like 'first[second][third]' ? |
|
326 | - if (strpos($key, '[') !== false) { |
|
327 | - // turn it into an actual array |
|
328 | - $key = str_replace(']', '', $key); |
|
329 | - $keys = explode('[', $key); |
|
330 | - $key = array_shift($keys); |
|
331 | - if ($callback === 'match') { |
|
332 | - $real_key = $this->match($key, $request_params, $default, 'key'); |
|
333 | - $key = $real_key ? $real_key : $key; |
|
334 | - } |
|
335 | - // check if top level key exists |
|
336 | - if (isset($request_params[ $key ])) { |
|
337 | - // build a new key to pass along like: 'second[third]' |
|
338 | - // or just 'second' depending on depth of keys |
|
339 | - $key_string = array_shift($keys); |
|
340 | - if (! empty($keys)) { |
|
341 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
342 | - } |
|
343 | - return $this->requestParameterDrillDown( |
|
344 | - $key_string, |
|
345 | - $default, |
|
346 | - $callback, |
|
347 | - $request_params[ $key ] |
|
348 | - ); |
|
349 | - } |
|
350 | - } |
|
351 | - if ($callback === 'is_set') { |
|
352 | - return isset($request_params[ $key ]); |
|
353 | - } |
|
354 | - if ($callback === 'match') { |
|
355 | - return $this->match($key, $request_params, $default); |
|
356 | - } |
|
357 | - return isset($request_params[ $key ]) |
|
358 | - ? $request_params[ $key ] |
|
359 | - : $default; |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * remove param |
|
365 | - * |
|
366 | - * @param $key |
|
367 | - * @param bool $unset_from_global_too |
|
368 | - */ |
|
369 | - public function unSetRequestParam($key, $unset_from_global_too = false) |
|
370 | - { |
|
371 | - unset($this->request[ $key ]); |
|
372 | - if ($unset_from_global_too) { |
|
373 | - unset($_REQUEST[ $key ]); |
|
374 | - } |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - /** |
|
379 | - * @return string |
|
380 | - */ |
|
381 | - public function ipAddress() |
|
382 | - { |
|
383 | - return $this->ip_address; |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * attempt to get IP address of current visitor from server |
|
389 | - * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
390 | - * |
|
391 | - * @access public |
|
392 | - * @return string |
|
393 | - */ |
|
394 | - private function visitorIp() |
|
395 | - { |
|
396 | - $visitor_ip = '0.0.0.0'; |
|
397 | - $server_keys = array( |
|
398 | - 'HTTP_CLIENT_IP', |
|
399 | - 'HTTP_X_FORWARDED_FOR', |
|
400 | - 'HTTP_X_FORWARDED', |
|
401 | - 'HTTP_X_CLUSTER_CLIENT_IP', |
|
402 | - 'HTTP_FORWARDED_FOR', |
|
403 | - 'HTTP_FORWARDED', |
|
404 | - 'REMOTE_ADDR', |
|
405 | - ); |
|
406 | - foreach ($server_keys as $key) { |
|
407 | - if (isset($this->server[ $key ])) { |
|
408 | - foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
409 | - if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
410 | - $visitor_ip = $ip; |
|
411 | - } |
|
412 | - } |
|
413 | - } |
|
414 | - } |
|
415 | - return $visitor_ip; |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * @return string |
|
421 | - */ |
|
422 | - public function requestUri() |
|
423 | - { |
|
424 | - $request_uri = filter_input( |
|
425 | - INPUT_SERVER, |
|
426 | - 'REQUEST_URI', |
|
427 | - FILTER_SANITIZE_URL, |
|
428 | - FILTER_NULL_ON_FAILURE |
|
429 | - ); |
|
430 | - if (empty($request_uri)) { |
|
431 | - // fallback sanitization if the above fails |
|
432 | - $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
433 | - } |
|
434 | - return $request_uri; |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * @return string |
|
440 | - */ |
|
441 | - public function userAgent() |
|
442 | - { |
|
443 | - return $this->user_agent; |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * @param string $user_agent |
|
449 | - */ |
|
450 | - public function setUserAgent($user_agent = '') |
|
451 | - { |
|
452 | - if ($user_agent === '' || ! is_string($user_agent)) { |
|
453 | - $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
454 | - } |
|
455 | - $this->user_agent = $user_agent; |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * @return bool |
|
461 | - */ |
|
462 | - public function isBot() |
|
463 | - { |
|
464 | - return $this->is_bot; |
|
465 | - } |
|
466 | - |
|
467 | - |
|
468 | - /** |
|
469 | - * @param bool $is_bot |
|
470 | - */ |
|
471 | - public function setIsBot($is_bot) |
|
472 | - { |
|
473 | - $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - /** |
|
478 | - * @return bool |
|
479 | - */ |
|
480 | - public function isActivation() |
|
481 | - { |
|
482 | - return $this->request_type->isActivation(); |
|
483 | - } |
|
484 | - |
|
485 | - |
|
486 | - /** |
|
487 | - * @param $is_activation |
|
488 | - * @return bool |
|
489 | - */ |
|
490 | - public function setIsActivation($is_activation) |
|
491 | - { |
|
492 | - return $this->request_type->setIsActivation($is_activation); |
|
493 | - } |
|
494 | - |
|
495 | - |
|
496 | - /** |
|
497 | - * @return bool |
|
498 | - */ |
|
499 | - public function isAdmin() |
|
500 | - { |
|
501 | - return $this->request_type->isAdmin(); |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - /** |
|
506 | - * @return bool |
|
507 | - */ |
|
508 | - public function isAdminAjax() |
|
509 | - { |
|
510 | - return $this->request_type->isAdminAjax(); |
|
511 | - } |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * @return bool |
|
516 | - */ |
|
517 | - public function isAjax() |
|
518 | - { |
|
519 | - return $this->request_type->isAjax(); |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - /** |
|
524 | - * @return bool |
|
525 | - */ |
|
526 | - public function isEeAjax() |
|
527 | - { |
|
528 | - return $this->request_type->isEeAjax(); |
|
529 | - } |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * @return bool |
|
534 | - */ |
|
535 | - public function isOtherAjax() |
|
536 | - { |
|
537 | - return $this->request_type->isOtherAjax(); |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * @return bool |
|
543 | - */ |
|
544 | - public function isApi() |
|
545 | - { |
|
546 | - return $this->request_type->isApi(); |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * @return bool |
|
552 | - */ |
|
553 | - public function isCli() |
|
554 | - { |
|
555 | - return $this->request_type->isCli(); |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * @return bool |
|
561 | - */ |
|
562 | - public function isCron() |
|
563 | - { |
|
564 | - return $this->request_type->isCron(); |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * @return bool |
|
570 | - */ |
|
571 | - public function isFeed() |
|
572 | - { |
|
573 | - return $this->request_type->isFeed(); |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * @return bool |
|
579 | - */ |
|
580 | - public function isFrontend() |
|
581 | - { |
|
582 | - return $this->request_type->isFrontend(); |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * @return bool |
|
588 | - */ |
|
589 | - public function isFrontAjax() |
|
590 | - { |
|
591 | - return $this->request_type->isFrontAjax(); |
|
592 | - } |
|
593 | - |
|
594 | - |
|
595 | - /** |
|
596 | - * @return bool |
|
597 | - */ |
|
598 | - public function isIframe() |
|
599 | - { |
|
600 | - return $this->request_type->isIframe(); |
|
601 | - } |
|
602 | - |
|
603 | - |
|
604 | - /** |
|
605 | - * @return bool |
|
606 | - */ |
|
607 | - public function isWordPressApi() |
|
608 | - { |
|
609 | - return $this->request_type->isWordPressApi(); |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - |
|
614 | - /** |
|
615 | - * @return bool |
|
616 | - */ |
|
617 | - public function isWordPressHeartbeat() |
|
618 | - { |
|
619 | - return $this->request_type->isWordPressHeartbeat(); |
|
620 | - } |
|
621 | - |
|
622 | - |
|
623 | - |
|
624 | - /** |
|
625 | - * @return bool |
|
626 | - */ |
|
627 | - public function isWordPressScrape() |
|
628 | - { |
|
629 | - return $this->request_type->isWordPressScrape(); |
|
630 | - } |
|
631 | - |
|
632 | - |
|
633 | - /** |
|
634 | - * @return string |
|
635 | - */ |
|
636 | - public function slug() |
|
637 | - { |
|
638 | - return $this->request_type->slug(); |
|
639 | - } |
|
20 | + /** |
|
21 | + * $_GET parameters |
|
22 | + * |
|
23 | + * @var array $get |
|
24 | + */ |
|
25 | + private $get; |
|
26 | + |
|
27 | + /** |
|
28 | + * $_POST parameters |
|
29 | + * |
|
30 | + * @var array $post |
|
31 | + */ |
|
32 | + private $post; |
|
33 | + |
|
34 | + /** |
|
35 | + * $_COOKIE parameters |
|
36 | + * |
|
37 | + * @var array $cookie |
|
38 | + */ |
|
39 | + private $cookie; |
|
40 | + |
|
41 | + /** |
|
42 | + * $_SERVER parameters |
|
43 | + * |
|
44 | + * @var array $server |
|
45 | + */ |
|
46 | + private $server; |
|
47 | + |
|
48 | + /** |
|
49 | + * $_FILES parameters |
|
50 | + * |
|
51 | + * @var array $files |
|
52 | + */ |
|
53 | + private $files; |
|
54 | + |
|
55 | + /** |
|
56 | + * $_REQUEST parameters |
|
57 | + * |
|
58 | + * @var array $request |
|
59 | + */ |
|
60 | + private $request; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var RequestTypeContextCheckerInterface |
|
64 | + */ |
|
65 | + private $request_type; |
|
66 | + |
|
67 | + /** |
|
68 | + * IP address for request |
|
69 | + * |
|
70 | + * @var string $ip_address |
|
71 | + */ |
|
72 | + private $ip_address; |
|
73 | + |
|
74 | + /** |
|
75 | + * @var string $user_agent |
|
76 | + */ |
|
77 | + private $user_agent; |
|
78 | + |
|
79 | + /** |
|
80 | + * true if current user appears to be some kind of bot |
|
81 | + * |
|
82 | + * @var bool $is_bot |
|
83 | + */ |
|
84 | + private $is_bot; |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @param array $get |
|
89 | + * @param array $post |
|
90 | + * @param array $cookie |
|
91 | + * @param array $server |
|
92 | + * @param array $files |
|
93 | + */ |
|
94 | + public function __construct(array $get, array $post, array $cookie, array $server, array $files = array()) |
|
95 | + { |
|
96 | + // grab request vars |
|
97 | + $this->get = $get; |
|
98 | + $this->post = $post; |
|
99 | + $this->cookie = $cookie; |
|
100 | + $this->server = $server; |
|
101 | + $this->files = $files; |
|
102 | + $this->request = array_merge($this->get, $this->post); |
|
103 | + $this->ip_address = $this->visitorIp(); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @param RequestTypeContextCheckerInterface $type |
|
109 | + */ |
|
110 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
111 | + { |
|
112 | + $this->request_type = $type; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @return array |
|
118 | + */ |
|
119 | + public function getParams() |
|
120 | + { |
|
121 | + return $this->get; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @return array |
|
127 | + */ |
|
128 | + public function postParams() |
|
129 | + { |
|
130 | + return $this->post; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @return array |
|
136 | + */ |
|
137 | + public function cookieParams() |
|
138 | + { |
|
139 | + return $this->cookie; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @return array |
|
145 | + */ |
|
146 | + public function serverParams() |
|
147 | + { |
|
148 | + return $this->server; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + public function filesParams() |
|
156 | + { |
|
157 | + return $this->files; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * returns contents of $_REQUEST |
|
163 | + * |
|
164 | + * @return array |
|
165 | + */ |
|
166 | + public function requestParams() |
|
167 | + { |
|
168 | + return $this->request; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * @param $key |
|
174 | + * @param $value |
|
175 | + * @param bool $override_ee |
|
176 | + * @return void |
|
177 | + */ |
|
178 | + public function setRequestParam($key, $value, $override_ee = false) |
|
179 | + { |
|
180 | + // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
181 | + if ($key !== 'ee' |
|
182 | + || ($key === 'ee' && empty($this->request['ee'])) |
|
183 | + || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
|
184 | + ) { |
|
185 | + $this->request[ $key ] = $value; |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * returns the value for a request param if the given key exists |
|
192 | + * |
|
193 | + * @param $key |
|
194 | + * @param null $default |
|
195 | + * @return mixed |
|
196 | + */ |
|
197 | + public function getRequestParam($key, $default = null) |
|
198 | + { |
|
199 | + return $this->requestParameterDrillDown($key, $default, 'get'); |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * check if param exists |
|
205 | + * |
|
206 | + * @param $key |
|
207 | + * @return bool |
|
208 | + */ |
|
209 | + public function requestParamIsSet($key) |
|
210 | + { |
|
211 | + return $this->requestParameterDrillDown($key); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
217 | + * and return the value for the first match found |
|
218 | + * wildcards can be either of the following: |
|
219 | + * ? to represent a single character of any type |
|
220 | + * * to represent one or more characters of any type |
|
221 | + * |
|
222 | + * @param string $pattern |
|
223 | + * @param null|mixed $default |
|
224 | + * @return mixed |
|
225 | + */ |
|
226 | + public function getMatch($pattern, $default = null) |
|
227 | + { |
|
228 | + return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
234 | + * wildcards can be either of the following: |
|
235 | + * ? to represent a single character of any type |
|
236 | + * * to represent one or more characters of any type |
|
237 | + * returns true if a match is found or false if not |
|
238 | + * |
|
239 | + * @param string $pattern |
|
240 | + * @return bool |
|
241 | + */ |
|
242 | + public function matches($pattern) |
|
243 | + { |
|
244 | + return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
250 | + * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
251 | + * and used to search through the current request's parameter keys |
|
252 | + * @param array $request_params The array of request parameters to search through |
|
253 | + * @param mixed $default [optional] The value to be returned if no match is found. |
|
254 | + * Default is null |
|
255 | + * @param string $return [optional] Controls what kind of value is returned. |
|
256 | + * Options are: |
|
257 | + * 'bool' will return true or false if match is found or not |
|
258 | + * 'key' will return the first key found that matches the supplied pattern |
|
259 | + * 'value' will return the value for the first request parameter |
|
260 | + * whose key matches the supplied pattern |
|
261 | + * Default is 'value' |
|
262 | + * @return boolean|string |
|
263 | + */ |
|
264 | + private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
265 | + { |
|
266 | + $return = in_array($return, array('bool', 'key', 'value'), true) |
|
267 | + ? $return |
|
268 | + : 'is_set'; |
|
269 | + // replace wildcard chars with regex chars |
|
270 | + $pattern = str_replace( |
|
271 | + array("\*", "\?"), |
|
272 | + array('.*', '.'), |
|
273 | + preg_quote($pattern, '/') |
|
274 | + ); |
|
275 | + foreach ($request_params as $key => $request_param) { |
|
276 | + if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
277 | + // return value for request param |
|
278 | + if ($return === 'value') { |
|
279 | + return $request_params[ $key ]; |
|
280 | + } |
|
281 | + // or actual key or true just to indicate it was found |
|
282 | + return $return === 'key' ? $key : true; |
|
283 | + } |
|
284 | + } |
|
285 | + // match not found so return default value or false |
|
286 | + return $return === 'value' ? $default : false; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * the supplied key can be a simple string to represent a "top-level" request parameter |
|
292 | + * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
293 | + * by using square brackets to surround keys for deeper array elements. |
|
294 | + * For example : |
|
295 | + * if the supplied $key was: "first[second][third]" |
|
296 | + * then this will attempt to drill down into the request parameter array to find a value. |
|
297 | + * Given the following request parameters: |
|
298 | + * array( |
|
299 | + * 'first' => array( |
|
300 | + * 'second' => array( |
|
301 | + * 'third' => 'has a value' |
|
302 | + * ) |
|
303 | + * ) |
|
304 | + * ) |
|
305 | + * would return true if default parameters were set |
|
306 | + * |
|
307 | + * @param string $callback |
|
308 | + * @param $key |
|
309 | + * @param null $default |
|
310 | + * @param array $request_params |
|
311 | + * @return bool|mixed|null |
|
312 | + */ |
|
313 | + private function requestParameterDrillDown( |
|
314 | + $key, |
|
315 | + $default = null, |
|
316 | + $callback = 'is_set', |
|
317 | + array $request_params = array() |
|
318 | + ) { |
|
319 | + $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
320 | + ? $callback |
|
321 | + : 'is_set'; |
|
322 | + $request_params = ! empty($request_params) |
|
323 | + ? $request_params |
|
324 | + : $this->request; |
|
325 | + // does incoming key represent an array like 'first[second][third]' ? |
|
326 | + if (strpos($key, '[') !== false) { |
|
327 | + // turn it into an actual array |
|
328 | + $key = str_replace(']', '', $key); |
|
329 | + $keys = explode('[', $key); |
|
330 | + $key = array_shift($keys); |
|
331 | + if ($callback === 'match') { |
|
332 | + $real_key = $this->match($key, $request_params, $default, 'key'); |
|
333 | + $key = $real_key ? $real_key : $key; |
|
334 | + } |
|
335 | + // check if top level key exists |
|
336 | + if (isset($request_params[ $key ])) { |
|
337 | + // build a new key to pass along like: 'second[third]' |
|
338 | + // or just 'second' depending on depth of keys |
|
339 | + $key_string = array_shift($keys); |
|
340 | + if (! empty($keys)) { |
|
341 | + $key_string .= '[' . implode('][', $keys) . ']'; |
|
342 | + } |
|
343 | + return $this->requestParameterDrillDown( |
|
344 | + $key_string, |
|
345 | + $default, |
|
346 | + $callback, |
|
347 | + $request_params[ $key ] |
|
348 | + ); |
|
349 | + } |
|
350 | + } |
|
351 | + if ($callback === 'is_set') { |
|
352 | + return isset($request_params[ $key ]); |
|
353 | + } |
|
354 | + if ($callback === 'match') { |
|
355 | + return $this->match($key, $request_params, $default); |
|
356 | + } |
|
357 | + return isset($request_params[ $key ]) |
|
358 | + ? $request_params[ $key ] |
|
359 | + : $default; |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * remove param |
|
365 | + * |
|
366 | + * @param $key |
|
367 | + * @param bool $unset_from_global_too |
|
368 | + */ |
|
369 | + public function unSetRequestParam($key, $unset_from_global_too = false) |
|
370 | + { |
|
371 | + unset($this->request[ $key ]); |
|
372 | + if ($unset_from_global_too) { |
|
373 | + unset($_REQUEST[ $key ]); |
|
374 | + } |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + /** |
|
379 | + * @return string |
|
380 | + */ |
|
381 | + public function ipAddress() |
|
382 | + { |
|
383 | + return $this->ip_address; |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * attempt to get IP address of current visitor from server |
|
389 | + * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
390 | + * |
|
391 | + * @access public |
|
392 | + * @return string |
|
393 | + */ |
|
394 | + private function visitorIp() |
|
395 | + { |
|
396 | + $visitor_ip = '0.0.0.0'; |
|
397 | + $server_keys = array( |
|
398 | + 'HTTP_CLIENT_IP', |
|
399 | + 'HTTP_X_FORWARDED_FOR', |
|
400 | + 'HTTP_X_FORWARDED', |
|
401 | + 'HTTP_X_CLUSTER_CLIENT_IP', |
|
402 | + 'HTTP_FORWARDED_FOR', |
|
403 | + 'HTTP_FORWARDED', |
|
404 | + 'REMOTE_ADDR', |
|
405 | + ); |
|
406 | + foreach ($server_keys as $key) { |
|
407 | + if (isset($this->server[ $key ])) { |
|
408 | + foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
409 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
410 | + $visitor_ip = $ip; |
|
411 | + } |
|
412 | + } |
|
413 | + } |
|
414 | + } |
|
415 | + return $visitor_ip; |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * @return string |
|
421 | + */ |
|
422 | + public function requestUri() |
|
423 | + { |
|
424 | + $request_uri = filter_input( |
|
425 | + INPUT_SERVER, |
|
426 | + 'REQUEST_URI', |
|
427 | + FILTER_SANITIZE_URL, |
|
428 | + FILTER_NULL_ON_FAILURE |
|
429 | + ); |
|
430 | + if (empty($request_uri)) { |
|
431 | + // fallback sanitization if the above fails |
|
432 | + $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
433 | + } |
|
434 | + return $request_uri; |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * @return string |
|
440 | + */ |
|
441 | + public function userAgent() |
|
442 | + { |
|
443 | + return $this->user_agent; |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * @param string $user_agent |
|
449 | + */ |
|
450 | + public function setUserAgent($user_agent = '') |
|
451 | + { |
|
452 | + if ($user_agent === '' || ! is_string($user_agent)) { |
|
453 | + $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
454 | + } |
|
455 | + $this->user_agent = $user_agent; |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * @return bool |
|
461 | + */ |
|
462 | + public function isBot() |
|
463 | + { |
|
464 | + return $this->is_bot; |
|
465 | + } |
|
466 | + |
|
467 | + |
|
468 | + /** |
|
469 | + * @param bool $is_bot |
|
470 | + */ |
|
471 | + public function setIsBot($is_bot) |
|
472 | + { |
|
473 | + $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + /** |
|
478 | + * @return bool |
|
479 | + */ |
|
480 | + public function isActivation() |
|
481 | + { |
|
482 | + return $this->request_type->isActivation(); |
|
483 | + } |
|
484 | + |
|
485 | + |
|
486 | + /** |
|
487 | + * @param $is_activation |
|
488 | + * @return bool |
|
489 | + */ |
|
490 | + public function setIsActivation($is_activation) |
|
491 | + { |
|
492 | + return $this->request_type->setIsActivation($is_activation); |
|
493 | + } |
|
494 | + |
|
495 | + |
|
496 | + /** |
|
497 | + * @return bool |
|
498 | + */ |
|
499 | + public function isAdmin() |
|
500 | + { |
|
501 | + return $this->request_type->isAdmin(); |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + /** |
|
506 | + * @return bool |
|
507 | + */ |
|
508 | + public function isAdminAjax() |
|
509 | + { |
|
510 | + return $this->request_type->isAdminAjax(); |
|
511 | + } |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * @return bool |
|
516 | + */ |
|
517 | + public function isAjax() |
|
518 | + { |
|
519 | + return $this->request_type->isAjax(); |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + /** |
|
524 | + * @return bool |
|
525 | + */ |
|
526 | + public function isEeAjax() |
|
527 | + { |
|
528 | + return $this->request_type->isEeAjax(); |
|
529 | + } |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * @return bool |
|
534 | + */ |
|
535 | + public function isOtherAjax() |
|
536 | + { |
|
537 | + return $this->request_type->isOtherAjax(); |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * @return bool |
|
543 | + */ |
|
544 | + public function isApi() |
|
545 | + { |
|
546 | + return $this->request_type->isApi(); |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * @return bool |
|
552 | + */ |
|
553 | + public function isCli() |
|
554 | + { |
|
555 | + return $this->request_type->isCli(); |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * @return bool |
|
561 | + */ |
|
562 | + public function isCron() |
|
563 | + { |
|
564 | + return $this->request_type->isCron(); |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * @return bool |
|
570 | + */ |
|
571 | + public function isFeed() |
|
572 | + { |
|
573 | + return $this->request_type->isFeed(); |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * @return bool |
|
579 | + */ |
|
580 | + public function isFrontend() |
|
581 | + { |
|
582 | + return $this->request_type->isFrontend(); |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * @return bool |
|
588 | + */ |
|
589 | + public function isFrontAjax() |
|
590 | + { |
|
591 | + return $this->request_type->isFrontAjax(); |
|
592 | + } |
|
593 | + |
|
594 | + |
|
595 | + /** |
|
596 | + * @return bool |
|
597 | + */ |
|
598 | + public function isIframe() |
|
599 | + { |
|
600 | + return $this->request_type->isIframe(); |
|
601 | + } |
|
602 | + |
|
603 | + |
|
604 | + /** |
|
605 | + * @return bool |
|
606 | + */ |
|
607 | + public function isWordPressApi() |
|
608 | + { |
|
609 | + return $this->request_type->isWordPressApi(); |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + |
|
614 | + /** |
|
615 | + * @return bool |
|
616 | + */ |
|
617 | + public function isWordPressHeartbeat() |
|
618 | + { |
|
619 | + return $this->request_type->isWordPressHeartbeat(); |
|
620 | + } |
|
621 | + |
|
622 | + |
|
623 | + |
|
624 | + /** |
|
625 | + * @return bool |
|
626 | + */ |
|
627 | + public function isWordPressScrape() |
|
628 | + { |
|
629 | + return $this->request_type->isWordPressScrape(); |
|
630 | + } |
|
631 | + |
|
632 | + |
|
633 | + /** |
|
634 | + * @return string |
|
635 | + */ |
|
636 | + public function slug() |
|
637 | + { |
|
638 | + return $this->request_type->slug(); |
|
639 | + } |
|
640 | 640 | } |
@@ -25,80 +25,80 @@ |
||
25 | 25 | class BootstrapRequestResponseObjects |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * @type LegacyRequestInterface $legacy_request |
|
30 | - */ |
|
31 | - protected $legacy_request; |
|
28 | + /** |
|
29 | + * @type LegacyRequestInterface $legacy_request |
|
30 | + */ |
|
31 | + protected $legacy_request; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @type LoaderInterface $loader |
|
35 | - */ |
|
36 | - protected $loader; |
|
33 | + /** |
|
34 | + * @type LoaderInterface $loader |
|
35 | + */ |
|
36 | + protected $loader; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @var RequestInterface $request |
|
40 | - */ |
|
41 | - protected $request; |
|
38 | + /** |
|
39 | + * @var RequestInterface $request |
|
40 | + */ |
|
41 | + protected $request; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @var ResponseInterface $response |
|
45 | - */ |
|
46 | - protected $response; |
|
43 | + /** |
|
44 | + * @var ResponseInterface $response |
|
45 | + */ |
|
46 | + protected $response; |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * BootstrapRequestResponseObjects constructor. |
|
51 | - * |
|
52 | - * @param LoaderInterface $loader |
|
53 | - */ |
|
54 | - public function __construct(LoaderInterface $loader) |
|
55 | - { |
|
56 | - $this->loader = $loader; |
|
57 | - } |
|
49 | + /** |
|
50 | + * BootstrapRequestResponseObjects constructor. |
|
51 | + * |
|
52 | + * @param LoaderInterface $loader |
|
53 | + */ |
|
54 | + public function __construct(LoaderInterface $loader) |
|
55 | + { |
|
56 | + $this->loader = $loader; |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public function buildRequestResponse() |
|
64 | - { |
|
65 | - // load our Request and Response objects |
|
66 | - $this->request = new Request($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES); |
|
67 | - $this->response = new Response(); |
|
68 | - } |
|
60 | + /** |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public function buildRequestResponse() |
|
64 | + { |
|
65 | + // load our Request and Response objects |
|
66 | + $this->request = new Request($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES); |
|
67 | + $this->response = new Response(); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * @return void |
|
73 | - * @throws InvalidArgumentException |
|
74 | - */ |
|
75 | - public function shareRequestResponse() |
|
76 | - { |
|
77 | - $this->loader->share('EventEspresso\core\services\request\Request', $this->request); |
|
78 | - $this->loader->share('EventEspresso\core\services\request\Response', $this->response); |
|
79 | - EE_Dependency_Map::instance()->setRequest($this->request); |
|
80 | - EE_Dependency_Map::instance()->setResponse($this->response); |
|
81 | - } |
|
71 | + /** |
|
72 | + * @return void |
|
73 | + * @throws InvalidArgumentException |
|
74 | + */ |
|
75 | + public function shareRequestResponse() |
|
76 | + { |
|
77 | + $this->loader->share('EventEspresso\core\services\request\Request', $this->request); |
|
78 | + $this->loader->share('EventEspresso\core\services\request\Response', $this->response); |
|
79 | + EE_Dependency_Map::instance()->setRequest($this->request); |
|
80 | + EE_Dependency_Map::instance()->setResponse($this->response); |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - /** |
|
85 | - * @return void |
|
86 | - * @throws InvalidArgumentException |
|
87 | - * @throws EE_Error |
|
88 | - */ |
|
89 | - public function setupLegacyRequest() |
|
90 | - { |
|
91 | - espresso_load_required( |
|
92 | - 'EE_Request', |
|
93 | - EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
94 | - ); |
|
95 | - $this->legacy_request = new EE_Request($_GET, $_POST, $_COOKIE, $_SERVER); |
|
96 | - $this->legacy_request->setRequest($this->request); |
|
97 | - $this->legacy_request->admin = $this->request->isAdmin(); |
|
98 | - $this->legacy_request->ajax = $this->request->isAjax(); |
|
99 | - $this->legacy_request->front_ajax = $this->request->isFrontAjax(); |
|
100 | - EE_Dependency_Map::instance()->setLegacyRequest($this->legacy_request); |
|
101 | - $this->loader->share('EE_Request', $this->legacy_request); |
|
102 | - $this->loader->share('EventEspresso\core\services\request\LegacyRequestInterface', $this->legacy_request); |
|
103 | - } |
|
84 | + /** |
|
85 | + * @return void |
|
86 | + * @throws InvalidArgumentException |
|
87 | + * @throws EE_Error |
|
88 | + */ |
|
89 | + public function setupLegacyRequest() |
|
90 | + { |
|
91 | + espresso_load_required( |
|
92 | + 'EE_Request', |
|
93 | + EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
94 | + ); |
|
95 | + $this->legacy_request = new EE_Request($_GET, $_POST, $_COOKIE, $_SERVER); |
|
96 | + $this->legacy_request->setRequest($this->request); |
|
97 | + $this->legacy_request->admin = $this->request->isAdmin(); |
|
98 | + $this->legacy_request->ajax = $this->request->isAjax(); |
|
99 | + $this->legacy_request->front_ajax = $this->request->isFrontAjax(); |
|
100 | + EE_Dependency_Map::instance()->setLegacyRequest($this->legacy_request); |
|
101 | + $this->loader->share('EE_Request', $this->legacy_request); |
|
102 | + $this->loader->share('EventEspresso\core\services\request\LegacyRequestInterface', $this->legacy_request); |
|
103 | + } |
|
104 | 104 | } |
@@ -11,606 +11,606 @@ |
||
11 | 11 | class EEG_Paypal_Pro extends EE_Onsite_Gateway |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @var $_paypal_api_username string |
|
16 | - */ |
|
17 | - protected $_api_username = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var $_api_password string |
|
21 | - */ |
|
22 | - protected $_api_password = null; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var $_api_signature string |
|
26 | - */ |
|
27 | - protected $_api_signature = null; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var $_credit_card_types array with the keys for credit card types accepted on this account |
|
31 | - */ |
|
32 | - protected $_credit_card_types = null; |
|
33 | - |
|
34 | - protected $_currencies_supported = array( |
|
35 | - 'USD', |
|
36 | - 'GBP', |
|
37 | - 'CAD', |
|
38 | - 'AUD', |
|
39 | - 'BRL', |
|
40 | - 'CHF', |
|
41 | - 'CZK', |
|
42 | - 'DKK', |
|
43 | - 'EUR', |
|
44 | - 'HKD', |
|
45 | - 'HUF', |
|
46 | - 'ILS', |
|
47 | - 'JPY', |
|
48 | - 'MXN', |
|
49 | - 'MYR', |
|
50 | - 'NOK', |
|
51 | - 'NZD', |
|
52 | - 'PHP', |
|
53 | - 'PLN', |
|
54 | - 'SEK', |
|
55 | - 'SGD', |
|
56 | - 'THB', |
|
57 | - 'TRY', |
|
58 | - 'TWD', |
|
59 | - 'RUB', |
|
60 | - 'INR', |
|
61 | - ); |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param EEI_Payment $payment |
|
67 | - * @param array $billing_info { |
|
68 | - * @type string $credit_card |
|
69 | - * @type string $credit_card_type |
|
70 | - * @type string $exp_month always 2 characters |
|
71 | - * @type string $exp_year always 4 characters |
|
72 | - * @type string $cvv |
|
73 | - * } |
|
74 | - * @see parent::do_direct_payment for more info |
|
75 | - * @return EE_Payment|EEI_Payment |
|
76 | - * @throws EE_Error |
|
77 | - */ |
|
78 | - public function do_direct_payment($payment, $billing_info = null) |
|
79 | - { |
|
80 | - $transaction = $payment->transaction(); |
|
81 | - if (! $transaction instanceof EEI_Transaction) { |
|
82 | - throw new EE_Error( |
|
83 | - esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso') |
|
84 | - ); |
|
85 | - } |
|
86 | - $primary_registrant = $transaction->primary_registration(); |
|
87 | - if (! $primary_registrant instanceof EEI_Registration) { |
|
88 | - throw new EE_Error( |
|
89 | - esc_html__( |
|
90 | - 'No primary registration on transaction while paying with PayPal Pro.', |
|
91 | - 'event_espresso' |
|
92 | - ) |
|
93 | - ); |
|
94 | - } |
|
95 | - $attendee = $primary_registrant->attendee(); |
|
96 | - if (! $attendee instanceof EEI_Attendee) { |
|
97 | - throw new EE_Error( |
|
98 | - esc_html__( |
|
99 | - 'No attendee on primary registration while paying with PayPal Pro.', |
|
100 | - 'event_espresso' |
|
101 | - ) |
|
102 | - ); |
|
103 | - } |
|
104 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
105 | - $order_description = substr($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
106 | - // charge for the full amount. Show itemized list |
|
107 | - if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
108 | - $item_num = 1; |
|
109 | - $total_line_item = $transaction->total_line_item(); |
|
110 | - $order_items = array(); |
|
111 | - foreach ($total_line_item->get_items() as $line_item) { |
|
112 | - // ignore line items with a quantity of 0 |
|
113 | - if ($line_item->quantity() == 0) { |
|
114 | - continue; |
|
115 | - } |
|
116 | - // For percent items, whose unit_price is 0, use the total instead. |
|
117 | - if ($line_item->is_percent()) { |
|
118 | - $unit_price = $line_item->total(); |
|
119 | - $line_item_quantity = 1; |
|
120 | - } else { |
|
121 | - $unit_price = $line_item->unit_price(); |
|
122 | - $line_item_quantity = $line_item->quantity(); |
|
123 | - } |
|
124 | - $item = array( |
|
125 | - // Item Name. 127 char max. |
|
126 | - 'l_name' => substr( |
|
127 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
128 | - 0, |
|
129 | - 127 |
|
130 | - ), |
|
131 | - // Item description. 127 char max. |
|
132 | - 'l_desc' => substr( |
|
133 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
134 | - 0, |
|
135 | - 127 |
|
136 | - ), |
|
137 | - // Cost of individual item. |
|
138 | - 'l_amt' => $unit_price, |
|
139 | - // Item Number. 127 char max. |
|
140 | - 'l_number' => $item_num++, |
|
141 | - // Item quantity. Must be any positive integer. |
|
142 | - 'l_qty' => $line_item_quantity, |
|
143 | - // Item's sales tax amount. |
|
144 | - 'l_taxamt' => '', |
|
145 | - // eBay auction number of item. |
|
146 | - 'l_ebayitemnumber' => '', |
|
147 | - // eBay transaction ID of purchased item. |
|
148 | - 'l_ebayitemauctiontxnid' => '', |
|
149 | - // eBay order ID for the item. |
|
150 | - 'l_ebayitemorderid' => '', |
|
151 | - ); |
|
152 | - // add to array of all items |
|
153 | - array_push($order_items, $item); |
|
154 | - } |
|
155 | - $item_amount = $total_line_item->get_items_total(); |
|
156 | - $tax_amount = $total_line_item->get_total_tax(); |
|
157 | - } else { |
|
158 | - $order_items = array(); |
|
159 | - $item_amount = $payment->amount(); |
|
160 | - $tax_amount = 0; |
|
161 | - array_push($order_items, array( |
|
162 | - // Item Name. 127 char max. |
|
163 | - 'l_name' => substr( |
|
164 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
165 | - 0, |
|
166 | - 127 |
|
167 | - ), |
|
168 | - // Item description. 127 char max. |
|
169 | - 'l_desc' => substr( |
|
170 | - $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
171 | - 0, |
|
172 | - 127 |
|
173 | - ), |
|
174 | - // Cost of individual item. |
|
175 | - 'l_amt' => $payment->amount(), |
|
176 | - // Item Number. 127 char max. |
|
177 | - 'l_number' => 1, |
|
178 | - // Item quantity. Must be any positive integer. |
|
179 | - 'l_qty' => 1, |
|
180 | - )); |
|
181 | - } |
|
182 | - // Populate data arrays with order data. |
|
183 | - $DPFields = array( |
|
184 | - // How you want to obtain payment ? |
|
185 | - // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture. |
|
186 | - // Sale indicates that this is a final sale for which you are requesting payment. Default is Sale. |
|
187 | - 'paymentaction' => 'Sale', |
|
188 | - // Required. IP address of the payer's browser. |
|
189 | - 'ipaddress' => $_SERVER['REMOTE_ADDR'], |
|
190 | - // Flag to determine whether you want the results returned by FMF. 1 or 0. Default is 0. |
|
191 | - 'returnfmfdetails' => '1', |
|
192 | - ); |
|
193 | - $CCDetails = array( |
|
194 | - // Required. Type of credit card. Visa, MasterCard, Discover, Amex, Maestro, Solo. |
|
195 | - // If Maestro or Solo, the currency code must be GBP. |
|
196 | - // In addition, either start date or issue number must be specified. |
|
197 | - 'creditcardtype' => $billing_info['credit_card_type'], |
|
198 | - // Required. Credit card number. No spaces or punctuation. |
|
199 | - 'acct' => $billing_info['credit_card'], |
|
200 | - // Required. Credit card expiration date. Format is MMYYYY |
|
201 | - 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
202 | - // Requirements determined by your PayPal account settings. Security digits for credit card. |
|
203 | - 'cvv2' => $billing_info['cvv'], |
|
204 | - ); |
|
205 | - $PayerInfo = array( |
|
206 | - // Email address of payer. |
|
207 | - 'email' => $billing_info['email'], |
|
208 | - // Unique PayPal customer ID for payer. |
|
209 | - 'payerid' => '', |
|
210 | - // Status of payer. Values are verified or unverified |
|
211 | - 'payerstatus' => '', |
|
212 | - // Payer's business name. |
|
213 | - 'business' => '', |
|
214 | - ); |
|
215 | - $PayerName = array( |
|
216 | - // Payer's salutation. 20 char max. |
|
217 | - 'salutation' => '', |
|
218 | - // Payer's first name. 25 char max. |
|
219 | - 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
220 | - // Payer's middle name. 25 char max. |
|
221 | - 'middlename' => '', |
|
222 | - // Payer's last name. 25 char max. |
|
223 | - 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
224 | - // Payer's suffix. 12 char max. |
|
225 | - 'suffix' => '', |
|
226 | - ); |
|
227 | - $BillingAddress = array( |
|
228 | - // Required. First street address. |
|
229 | - 'street' => $billing_info['address'], |
|
230 | - // Second street address. |
|
231 | - 'street2' => $billing_info['address2'], |
|
232 | - // Required. Name of City. |
|
233 | - 'city' => $billing_info['city'], |
|
234 | - // Required. Name of State or Province. |
|
235 | - 'state' => substr($billing_info['state'], 0, 40), |
|
236 | - // Required. Country code. |
|
237 | - 'countrycode' => $billing_info['country'], |
|
238 | - // Required. Postal code of payer. |
|
239 | - 'zip' => $billing_info['zip'], |
|
240 | - ); |
|
241 | - // check if the registration info contains the needed fields for paypal pro |
|
242 | - // (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/) |
|
243 | - if ($attendee->address() && $attendee->city() && $attendee->country_ID()) { |
|
244 | - $use_registration_address_info = true; |
|
245 | - } else { |
|
246 | - $use_registration_address_info = false; |
|
247 | - } |
|
248 | - // so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. |
|
249 | - // If not, use the billing info again |
|
250 | - $ShippingAddress = array( |
|
251 | - 'shiptoname' => substr($use_registration_address_info |
|
252 | - ? $attendee->full_name() |
|
253 | - : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
254 | - 'shiptostreet' => substr($use_registration_address_info |
|
255 | - ? $attendee->address() |
|
256 | - : $billing_info['address'], 0, 100), |
|
257 | - 'shiptostreet2' => substr($use_registration_address_info |
|
258 | - ? $attendee->address2() : $billing_info['address2'], 0, 100), |
|
259 | - 'shiptocity' => substr($use_registration_address_info |
|
260 | - ? $attendee->city() |
|
261 | - : $billing_info['city'], 0, 40), |
|
262 | - 'state' => substr($use_registration_address_info |
|
263 | - ? $attendee->state_name() |
|
264 | - : $billing_info['state'], 0, 40), |
|
265 | - 'shiptocountry' => $use_registration_address_info |
|
266 | - ? $attendee->country_ID() |
|
267 | - : $billing_info['country'], |
|
268 | - 'shiptozip' => substr($use_registration_address_info |
|
269 | - ? $attendee->zip() |
|
270 | - : $billing_info['zip'], 0, 20), |
|
271 | - 'shiptophonenum' => substr($use_registration_address_info |
|
272 | - ? $attendee->phone() |
|
273 | - : $billing_info['phone'], 0, 20), |
|
274 | - ); |
|
275 | - $PaymentDetails = array( |
|
276 | - // Required. Total amount of order, including shipping, handling, and tax. |
|
277 | - 'amt' => $gateway_formatter->formatCurrency($payment->amount()), |
|
278 | - // Required. Three-letter currency code. Default is USD. |
|
279 | - 'currencycode' => $payment->currency_code(), |
|
280 | - // Required if you include itemized cart details. (L_AMTn, etc.) |
|
281 | - // Subtotal of items not including S&H, or tax. |
|
282 | - 'itemamt' => $gateway_formatter->formatCurrency($item_amount),// |
|
283 | - // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
|
284 | - 'shippingamt' => '', |
|
285 | - // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
|
286 | - 'handlingamt' => '', |
|
287 | - // Required if you specify itemized cart tax details. |
|
288 | - // Sum of tax for all items on the order. Total sales tax. |
|
289 | - 'taxamt' => $gateway_formatter->formatCurrency($tax_amount), |
|
290 | - // Description of the order the customer is purchasing. 127 char max. |
|
291 | - 'desc' => $order_description, |
|
292 | - // Free-form field for your own use. 256 char max. |
|
293 | - 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
|
294 | - // Your own invoice or tracking number |
|
295 | - 'invnum' => wp_generate_password(12, false),// $transaction->ID(), |
|
296 | - // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
|
297 | - 'notifyurl' => '', |
|
298 | - 'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this |
|
299 | - ); |
|
300 | - // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
|
301 | - $PayPalRequestData = array( |
|
302 | - 'DPFields' => $DPFields, |
|
303 | - 'CCDetails' => $CCDetails, |
|
304 | - 'PayerInfo' => $PayerInfo, |
|
305 | - 'PayerName' => $PayerName, |
|
306 | - 'BillingAddress' => $BillingAddress, |
|
307 | - 'ShippingAddress' => $ShippingAddress, |
|
308 | - 'PaymentDetails' => $PaymentDetails, |
|
309 | - 'OrderItems' => $order_items, |
|
310 | - ); |
|
311 | - $this->_log_clean_request($PayPalRequestData, $payment); |
|
312 | - try { |
|
313 | - $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
|
314 | - // remove PCI-sensitive data so it doesn't get stored |
|
315 | - $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
316 | - if (isset($PayPalResult['L_ERRORCODE0']) && $PayPalResult['L_ERRORCODE0'] === '10002') { |
|
317 | - $message = esc_html__('PayPal did not accept your API username, password, or signature. Please double-check these credentials and if debug mode is on.', 'event_espresso'); |
|
318 | - } elseif (isset($PayPalResult['L_LONGMESSAGE0'])) { |
|
319 | - $message = $PayPalResult['L_LONGMESSAGE0']; |
|
320 | - } else { |
|
321 | - $message = $PayPalResult['ACK']; |
|
322 | - } |
|
323 | - if (empty($PayPalResult['RAWRESPONSE'])) { |
|
324 | - $payment->set_status($this->_pay_model->failed_status()); |
|
325 | - $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
326 | - $payment->set_details($PayPalResult); |
|
327 | - } else { |
|
328 | - if ($this->_APICallSuccessful($PayPalResult)) { |
|
329 | - $payment->set_status($this->_pay_model->approved_status()); |
|
330 | - } else { |
|
331 | - $payment->set_status($this->_pay_model->declined_status()); |
|
332 | - } |
|
333 | - // make sure we interpret the AMT as a float, not an international string |
|
334 | - // (where periods are thousand separators) |
|
335 | - $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
336 | - $payment->set_gateway_response($message); |
|
337 | - $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) |
|
338 | - ? $PayPalResult['TRANSACTIONID'] |
|
339 | - : null); |
|
340 | - $primary_registration_code = $primary_registrant instanceof EE_Registration |
|
341 | - ? $primary_registrant->reg_code() |
|
342 | - : ''; |
|
343 | - $payment->set_extra_accntng($primary_registration_code); |
|
344 | - $payment->set_details($PayPalResult); |
|
345 | - } |
|
346 | - } catch (Exception $e) { |
|
347 | - $payment->set_status($this->_pay_model->failed_status()); |
|
348 | - $payment->set_gateway_response($e->getMessage()); |
|
349 | - } |
|
350 | - // $payment->set_status( $this->_pay_model->declined_status() ); |
|
351 | - // $payment->set_gateway_response( '' ); |
|
352 | - return $payment; |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * CLeans out sensitive CC data and then logs it, and returns the cleaned request |
|
359 | - * |
|
360 | - * @param array $request |
|
361 | - * @param EEI_Payment $payment |
|
362 | - * @return void |
|
363 | - */ |
|
364 | - private function _log_clean_request($request, $payment) |
|
365 | - { |
|
366 | - $cleaned_request_data = $request; |
|
367 | - unset($cleaned_request_data['CCDetails']['acct']); |
|
368 | - unset($cleaned_request_data['CCDetails']['cvv2']); |
|
369 | - unset($cleaned_request_data['CCDetails']['expdate']); |
|
370 | - $this->log(array('Paypal Request' => $cleaned_request_data), $payment); |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * Cleans the response, logs it, and returns it |
|
377 | - * |
|
378 | - * @param array $response |
|
379 | - * @param EEI_Payment $payment |
|
380 | - * @return array cleaned |
|
381 | - */ |
|
382 | - private function _log_clean_response($response, $payment) |
|
383 | - { |
|
384 | - unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
|
385 | - unset($response['REQUESTDATA']['ACCT']); |
|
386 | - unset($response['REQUESTDATA']['EXPDATE']); |
|
387 | - unset($response['REQUESTDATA']['CVV2']); |
|
388 | - unset($response['RAWREQUEST']); |
|
389 | - $this->log(array('Paypal Response' => $response), $payment); |
|
390 | - return $response; |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - |
|
395 | - /** |
|
396 | - * @param $DataArray |
|
397 | - * @return array |
|
398 | - */ |
|
399 | - private function prep_and_curl_request($DataArray) |
|
400 | - { |
|
401 | - // Create empty holders for each portion of the NVP string |
|
402 | - $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP'; |
|
403 | - $CCDetailsNVP = ''; |
|
404 | - $PayerInfoNVP = ''; |
|
405 | - $PayerNameNVP = ''; |
|
406 | - $BillingAddressNVP = ''; |
|
407 | - $ShippingAddressNVP = ''; |
|
408 | - $PaymentDetailsNVP = ''; |
|
409 | - $OrderItemsNVP = ''; |
|
410 | - $Secure3DNVP = ''; |
|
411 | - // DP Fields |
|
412 | - $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
|
413 | - foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
|
414 | - $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
415 | - } |
|
416 | - // CC Details Fields |
|
417 | - $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
|
418 | - foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
|
419 | - $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
420 | - } |
|
421 | - // PayerInfo Type Fields |
|
422 | - $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
|
423 | - foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
|
424 | - $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
425 | - } |
|
426 | - // Payer Name Fields |
|
427 | - $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
|
428 | - foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
|
429 | - $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
430 | - } |
|
431 | - // Address Fields (Billing) |
|
432 | - $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
|
433 | - foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
|
434 | - $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
435 | - } |
|
436 | - // Payment Details Type Fields |
|
437 | - $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
|
438 | - foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
|
439 | - $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
440 | - } |
|
441 | - // Payment Details Item Type Fields |
|
442 | - $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
|
443 | - $n = 0; |
|
444 | - foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
|
445 | - $CurrentItem = $OrderItems[ $OrderItemsVar ]; |
|
446 | - foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
|
447 | - $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
448 | - } |
|
449 | - $n++; |
|
450 | - } |
|
451 | - // Ship To Address Fields |
|
452 | - $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
|
453 | - foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
|
454 | - $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
455 | - } |
|
456 | - // 3D Secure Fields |
|
457 | - $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
|
458 | - foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
|
459 | - $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
460 | - } |
|
461 | - // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
|
462 | - $NVPRequest = 'USER=' |
|
463 | - . $this->_api_username |
|
464 | - . '&PWD=' |
|
465 | - . $this->_api_password |
|
466 | - . '&VERSION=64.0' |
|
467 | - . '&SIGNATURE=' |
|
468 | - . $this->_api_signature |
|
469 | - . $DPFieldsNVP |
|
470 | - . $CCDetailsNVP |
|
471 | - . $PayerInfoNVP |
|
472 | - . $PayerNameNVP |
|
473 | - . $BillingAddressNVP |
|
474 | - . $PaymentDetailsNVP |
|
475 | - . $OrderItemsNVP |
|
476 | - . $ShippingAddressNVP |
|
477 | - . $Secure3DNVP; |
|
478 | - $NVPResponse = $this->_CURLRequest($NVPRequest); |
|
479 | - $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
|
480 | - $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
|
481 | - $Errors = $this->_GetErrors($NVPResponseArray); |
|
482 | - $NVPResponseArray['ERRORS'] = $Errors; |
|
483 | - $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; |
|
484 | - $NVPResponseArray['RAWREQUEST'] = $NVPRequest; |
|
485 | - $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; |
|
486 | - return $NVPResponseArray; |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * @param $Request |
|
493 | - * @return mixed |
|
494 | - */ |
|
495 | - private function _CURLRequest($Request) |
|
496 | - { |
|
497 | - $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
|
498 | - $curl = curl_init(); |
|
499 | - curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true)); |
|
500 | - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
501 | - curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
502 | - curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
|
503 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
504 | - curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); |
|
505 | - curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
506 | - // execute the curl POST |
|
507 | - $Response = curl_exec($curl); |
|
508 | - curl_close($curl); |
|
509 | - return $Response; |
|
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * @param $NVPString |
|
516 | - * @return array |
|
517 | - */ |
|
518 | - private function _NVPToArray($NVPString) |
|
519 | - { |
|
520 | - // prepare responses into array |
|
521 | - $proArray = array(); |
|
522 | - while (strlen($NVPString)) { |
|
523 | - // name |
|
524 | - $keypos = strpos($NVPString, '='); |
|
525 | - $keyval = substr($NVPString, 0, $keypos); |
|
526 | - // value |
|
527 | - $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
|
528 | - $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
|
529 | - // decoding the response |
|
530 | - $proArray[ $keyval ] = urldecode($valval); |
|
531 | - $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
|
532 | - } |
|
533 | - return $proArray; |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - |
|
538 | - /** |
|
539 | - * @param array $PayPalResult |
|
540 | - * @return bool |
|
541 | - */ |
|
542 | - private function _APICallSuccessful($PayPalResult) |
|
543 | - { |
|
544 | - $approved = false; |
|
545 | - // check main response message from PayPal |
|
546 | - if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
547 | - $ack = strtoupper($PayPalResult['ACK']); |
|
548 | - $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
549 | - } |
|
550 | - return $approved; |
|
551 | - } |
|
552 | - |
|
553 | - |
|
554 | - |
|
555 | - /** |
|
556 | - * @param $DataArray |
|
557 | - * @return array |
|
558 | - */ |
|
559 | - private function _GetErrors($DataArray) |
|
560 | - { |
|
561 | - $Errors = array(); |
|
562 | - $n = 0; |
|
563 | - while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) { |
|
564 | - $LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : ''; |
|
565 | - $LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ]) |
|
566 | - ? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ] |
|
567 | - : ''; |
|
568 | - $LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ]) |
|
569 | - ? $DataArray[ 'L_LONGMESSAGE' . $n . '' ] |
|
570 | - : ''; |
|
571 | - $LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ]) |
|
572 | - ? $DataArray[ 'L_SEVERITYCODE' . $n . '' ] |
|
573 | - : ''; |
|
574 | - $CurrentItem = array( |
|
575 | - 'L_ERRORCODE' => $LErrorCode, |
|
576 | - 'L_SHORTMESSAGE' => $LShortMessage, |
|
577 | - 'L_LONGMESSAGE' => $LLongMessage, |
|
578 | - 'L_SEVERITYCODE' => $LSeverityCode, |
|
579 | - ); |
|
580 | - array_push($Errors, $CurrentItem); |
|
581 | - $n++; |
|
582 | - } |
|
583 | - return $Errors; |
|
584 | - } |
|
585 | - |
|
586 | - |
|
587 | - |
|
588 | - /** |
|
589 | - * nothing to see here... move along.... |
|
590 | - * |
|
591 | - * @access protected |
|
592 | - * @param $Errors |
|
593 | - * @return string |
|
594 | - */ |
|
595 | - private function _DisplayErrors($Errors) |
|
596 | - { |
|
597 | - $error = ''; |
|
598 | - foreach ($Errors as $ErrorVar => $ErrorVal) { |
|
599 | - $CurrentError = $Errors[ $ErrorVar ]; |
|
600 | - foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
|
601 | - $CurrentVarName = ''; |
|
602 | - if ($CurrentErrorVar == 'L_ERRORCODE') { |
|
603 | - $CurrentVarName = 'Error Code'; |
|
604 | - } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') { |
|
605 | - $CurrentVarName = 'Short Message'; |
|
606 | - } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') { |
|
607 | - $CurrentVarName = 'Long Message'; |
|
608 | - } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
|
609 | - $CurrentVarName = 'Severity Code'; |
|
610 | - } |
|
611 | - $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
612 | - } |
|
613 | - } |
|
614 | - return $error; |
|
615 | - } |
|
14 | + /** |
|
15 | + * @var $_paypal_api_username string |
|
16 | + */ |
|
17 | + protected $_api_username = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var $_api_password string |
|
21 | + */ |
|
22 | + protected $_api_password = null; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var $_api_signature string |
|
26 | + */ |
|
27 | + protected $_api_signature = null; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var $_credit_card_types array with the keys for credit card types accepted on this account |
|
31 | + */ |
|
32 | + protected $_credit_card_types = null; |
|
33 | + |
|
34 | + protected $_currencies_supported = array( |
|
35 | + 'USD', |
|
36 | + 'GBP', |
|
37 | + 'CAD', |
|
38 | + 'AUD', |
|
39 | + 'BRL', |
|
40 | + 'CHF', |
|
41 | + 'CZK', |
|
42 | + 'DKK', |
|
43 | + 'EUR', |
|
44 | + 'HKD', |
|
45 | + 'HUF', |
|
46 | + 'ILS', |
|
47 | + 'JPY', |
|
48 | + 'MXN', |
|
49 | + 'MYR', |
|
50 | + 'NOK', |
|
51 | + 'NZD', |
|
52 | + 'PHP', |
|
53 | + 'PLN', |
|
54 | + 'SEK', |
|
55 | + 'SGD', |
|
56 | + 'THB', |
|
57 | + 'TRY', |
|
58 | + 'TWD', |
|
59 | + 'RUB', |
|
60 | + 'INR', |
|
61 | + ); |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param EEI_Payment $payment |
|
67 | + * @param array $billing_info { |
|
68 | + * @type string $credit_card |
|
69 | + * @type string $credit_card_type |
|
70 | + * @type string $exp_month always 2 characters |
|
71 | + * @type string $exp_year always 4 characters |
|
72 | + * @type string $cvv |
|
73 | + * } |
|
74 | + * @see parent::do_direct_payment for more info |
|
75 | + * @return EE_Payment|EEI_Payment |
|
76 | + * @throws EE_Error |
|
77 | + */ |
|
78 | + public function do_direct_payment($payment, $billing_info = null) |
|
79 | + { |
|
80 | + $transaction = $payment->transaction(); |
|
81 | + if (! $transaction instanceof EEI_Transaction) { |
|
82 | + throw new EE_Error( |
|
83 | + esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso') |
|
84 | + ); |
|
85 | + } |
|
86 | + $primary_registrant = $transaction->primary_registration(); |
|
87 | + if (! $primary_registrant instanceof EEI_Registration) { |
|
88 | + throw new EE_Error( |
|
89 | + esc_html__( |
|
90 | + 'No primary registration on transaction while paying with PayPal Pro.', |
|
91 | + 'event_espresso' |
|
92 | + ) |
|
93 | + ); |
|
94 | + } |
|
95 | + $attendee = $primary_registrant->attendee(); |
|
96 | + if (! $attendee instanceof EEI_Attendee) { |
|
97 | + throw new EE_Error( |
|
98 | + esc_html__( |
|
99 | + 'No attendee on primary registration while paying with PayPal Pro.', |
|
100 | + 'event_espresso' |
|
101 | + ) |
|
102 | + ); |
|
103 | + } |
|
104 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
105 | + $order_description = substr($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
106 | + // charge for the full amount. Show itemized list |
|
107 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
108 | + $item_num = 1; |
|
109 | + $total_line_item = $transaction->total_line_item(); |
|
110 | + $order_items = array(); |
|
111 | + foreach ($total_line_item->get_items() as $line_item) { |
|
112 | + // ignore line items with a quantity of 0 |
|
113 | + if ($line_item->quantity() == 0) { |
|
114 | + continue; |
|
115 | + } |
|
116 | + // For percent items, whose unit_price is 0, use the total instead. |
|
117 | + if ($line_item->is_percent()) { |
|
118 | + $unit_price = $line_item->total(); |
|
119 | + $line_item_quantity = 1; |
|
120 | + } else { |
|
121 | + $unit_price = $line_item->unit_price(); |
|
122 | + $line_item_quantity = $line_item->quantity(); |
|
123 | + } |
|
124 | + $item = array( |
|
125 | + // Item Name. 127 char max. |
|
126 | + 'l_name' => substr( |
|
127 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
128 | + 0, |
|
129 | + 127 |
|
130 | + ), |
|
131 | + // Item description. 127 char max. |
|
132 | + 'l_desc' => substr( |
|
133 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
134 | + 0, |
|
135 | + 127 |
|
136 | + ), |
|
137 | + // Cost of individual item. |
|
138 | + 'l_amt' => $unit_price, |
|
139 | + // Item Number. 127 char max. |
|
140 | + 'l_number' => $item_num++, |
|
141 | + // Item quantity. Must be any positive integer. |
|
142 | + 'l_qty' => $line_item_quantity, |
|
143 | + // Item's sales tax amount. |
|
144 | + 'l_taxamt' => '', |
|
145 | + // eBay auction number of item. |
|
146 | + 'l_ebayitemnumber' => '', |
|
147 | + // eBay transaction ID of purchased item. |
|
148 | + 'l_ebayitemauctiontxnid' => '', |
|
149 | + // eBay order ID for the item. |
|
150 | + 'l_ebayitemorderid' => '', |
|
151 | + ); |
|
152 | + // add to array of all items |
|
153 | + array_push($order_items, $item); |
|
154 | + } |
|
155 | + $item_amount = $total_line_item->get_items_total(); |
|
156 | + $tax_amount = $total_line_item->get_total_tax(); |
|
157 | + } else { |
|
158 | + $order_items = array(); |
|
159 | + $item_amount = $payment->amount(); |
|
160 | + $tax_amount = 0; |
|
161 | + array_push($order_items, array( |
|
162 | + // Item Name. 127 char max. |
|
163 | + 'l_name' => substr( |
|
164 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
165 | + 0, |
|
166 | + 127 |
|
167 | + ), |
|
168 | + // Item description. 127 char max. |
|
169 | + 'l_desc' => substr( |
|
170 | + $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
171 | + 0, |
|
172 | + 127 |
|
173 | + ), |
|
174 | + // Cost of individual item. |
|
175 | + 'l_amt' => $payment->amount(), |
|
176 | + // Item Number. 127 char max. |
|
177 | + 'l_number' => 1, |
|
178 | + // Item quantity. Must be any positive integer. |
|
179 | + 'l_qty' => 1, |
|
180 | + )); |
|
181 | + } |
|
182 | + // Populate data arrays with order data. |
|
183 | + $DPFields = array( |
|
184 | + // How you want to obtain payment ? |
|
185 | + // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture. |
|
186 | + // Sale indicates that this is a final sale for which you are requesting payment. Default is Sale. |
|
187 | + 'paymentaction' => 'Sale', |
|
188 | + // Required. IP address of the payer's browser. |
|
189 | + 'ipaddress' => $_SERVER['REMOTE_ADDR'], |
|
190 | + // Flag to determine whether you want the results returned by FMF. 1 or 0. Default is 0. |
|
191 | + 'returnfmfdetails' => '1', |
|
192 | + ); |
|
193 | + $CCDetails = array( |
|
194 | + // Required. Type of credit card. Visa, MasterCard, Discover, Amex, Maestro, Solo. |
|
195 | + // If Maestro or Solo, the currency code must be GBP. |
|
196 | + // In addition, either start date or issue number must be specified. |
|
197 | + 'creditcardtype' => $billing_info['credit_card_type'], |
|
198 | + // Required. Credit card number. No spaces or punctuation. |
|
199 | + 'acct' => $billing_info['credit_card'], |
|
200 | + // Required. Credit card expiration date. Format is MMYYYY |
|
201 | + 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
202 | + // Requirements determined by your PayPal account settings. Security digits for credit card. |
|
203 | + 'cvv2' => $billing_info['cvv'], |
|
204 | + ); |
|
205 | + $PayerInfo = array( |
|
206 | + // Email address of payer. |
|
207 | + 'email' => $billing_info['email'], |
|
208 | + // Unique PayPal customer ID for payer. |
|
209 | + 'payerid' => '', |
|
210 | + // Status of payer. Values are verified or unverified |
|
211 | + 'payerstatus' => '', |
|
212 | + // Payer's business name. |
|
213 | + 'business' => '', |
|
214 | + ); |
|
215 | + $PayerName = array( |
|
216 | + // Payer's salutation. 20 char max. |
|
217 | + 'salutation' => '', |
|
218 | + // Payer's first name. 25 char max. |
|
219 | + 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
220 | + // Payer's middle name. 25 char max. |
|
221 | + 'middlename' => '', |
|
222 | + // Payer's last name. 25 char max. |
|
223 | + 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
224 | + // Payer's suffix. 12 char max. |
|
225 | + 'suffix' => '', |
|
226 | + ); |
|
227 | + $BillingAddress = array( |
|
228 | + // Required. First street address. |
|
229 | + 'street' => $billing_info['address'], |
|
230 | + // Second street address. |
|
231 | + 'street2' => $billing_info['address2'], |
|
232 | + // Required. Name of City. |
|
233 | + 'city' => $billing_info['city'], |
|
234 | + // Required. Name of State or Province. |
|
235 | + 'state' => substr($billing_info['state'], 0, 40), |
|
236 | + // Required. Country code. |
|
237 | + 'countrycode' => $billing_info['country'], |
|
238 | + // Required. Postal code of payer. |
|
239 | + 'zip' => $billing_info['zip'], |
|
240 | + ); |
|
241 | + // check if the registration info contains the needed fields for paypal pro |
|
242 | + // (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/) |
|
243 | + if ($attendee->address() && $attendee->city() && $attendee->country_ID()) { |
|
244 | + $use_registration_address_info = true; |
|
245 | + } else { |
|
246 | + $use_registration_address_info = false; |
|
247 | + } |
|
248 | + // so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. |
|
249 | + // If not, use the billing info again |
|
250 | + $ShippingAddress = array( |
|
251 | + 'shiptoname' => substr($use_registration_address_info |
|
252 | + ? $attendee->full_name() |
|
253 | + : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
254 | + 'shiptostreet' => substr($use_registration_address_info |
|
255 | + ? $attendee->address() |
|
256 | + : $billing_info['address'], 0, 100), |
|
257 | + 'shiptostreet2' => substr($use_registration_address_info |
|
258 | + ? $attendee->address2() : $billing_info['address2'], 0, 100), |
|
259 | + 'shiptocity' => substr($use_registration_address_info |
|
260 | + ? $attendee->city() |
|
261 | + : $billing_info['city'], 0, 40), |
|
262 | + 'state' => substr($use_registration_address_info |
|
263 | + ? $attendee->state_name() |
|
264 | + : $billing_info['state'], 0, 40), |
|
265 | + 'shiptocountry' => $use_registration_address_info |
|
266 | + ? $attendee->country_ID() |
|
267 | + : $billing_info['country'], |
|
268 | + 'shiptozip' => substr($use_registration_address_info |
|
269 | + ? $attendee->zip() |
|
270 | + : $billing_info['zip'], 0, 20), |
|
271 | + 'shiptophonenum' => substr($use_registration_address_info |
|
272 | + ? $attendee->phone() |
|
273 | + : $billing_info['phone'], 0, 20), |
|
274 | + ); |
|
275 | + $PaymentDetails = array( |
|
276 | + // Required. Total amount of order, including shipping, handling, and tax. |
|
277 | + 'amt' => $gateway_formatter->formatCurrency($payment->amount()), |
|
278 | + // Required. Three-letter currency code. Default is USD. |
|
279 | + 'currencycode' => $payment->currency_code(), |
|
280 | + // Required if you include itemized cart details. (L_AMTn, etc.) |
|
281 | + // Subtotal of items not including S&H, or tax. |
|
282 | + 'itemamt' => $gateway_formatter->formatCurrency($item_amount),// |
|
283 | + // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
|
284 | + 'shippingamt' => '', |
|
285 | + // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
|
286 | + 'handlingamt' => '', |
|
287 | + // Required if you specify itemized cart tax details. |
|
288 | + // Sum of tax for all items on the order. Total sales tax. |
|
289 | + 'taxamt' => $gateway_formatter->formatCurrency($tax_amount), |
|
290 | + // Description of the order the customer is purchasing. 127 char max. |
|
291 | + 'desc' => $order_description, |
|
292 | + // Free-form field for your own use. 256 char max. |
|
293 | + 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
|
294 | + // Your own invoice or tracking number |
|
295 | + 'invnum' => wp_generate_password(12, false),// $transaction->ID(), |
|
296 | + // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
|
297 | + 'notifyurl' => '', |
|
298 | + 'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this |
|
299 | + ); |
|
300 | + // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
|
301 | + $PayPalRequestData = array( |
|
302 | + 'DPFields' => $DPFields, |
|
303 | + 'CCDetails' => $CCDetails, |
|
304 | + 'PayerInfo' => $PayerInfo, |
|
305 | + 'PayerName' => $PayerName, |
|
306 | + 'BillingAddress' => $BillingAddress, |
|
307 | + 'ShippingAddress' => $ShippingAddress, |
|
308 | + 'PaymentDetails' => $PaymentDetails, |
|
309 | + 'OrderItems' => $order_items, |
|
310 | + ); |
|
311 | + $this->_log_clean_request($PayPalRequestData, $payment); |
|
312 | + try { |
|
313 | + $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
|
314 | + // remove PCI-sensitive data so it doesn't get stored |
|
315 | + $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
316 | + if (isset($PayPalResult['L_ERRORCODE0']) && $PayPalResult['L_ERRORCODE0'] === '10002') { |
|
317 | + $message = esc_html__('PayPal did not accept your API username, password, or signature. Please double-check these credentials and if debug mode is on.', 'event_espresso'); |
|
318 | + } elseif (isset($PayPalResult['L_LONGMESSAGE0'])) { |
|
319 | + $message = $PayPalResult['L_LONGMESSAGE0']; |
|
320 | + } else { |
|
321 | + $message = $PayPalResult['ACK']; |
|
322 | + } |
|
323 | + if (empty($PayPalResult['RAWRESPONSE'])) { |
|
324 | + $payment->set_status($this->_pay_model->failed_status()); |
|
325 | + $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
326 | + $payment->set_details($PayPalResult); |
|
327 | + } else { |
|
328 | + if ($this->_APICallSuccessful($PayPalResult)) { |
|
329 | + $payment->set_status($this->_pay_model->approved_status()); |
|
330 | + } else { |
|
331 | + $payment->set_status($this->_pay_model->declined_status()); |
|
332 | + } |
|
333 | + // make sure we interpret the AMT as a float, not an international string |
|
334 | + // (where periods are thousand separators) |
|
335 | + $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
336 | + $payment->set_gateway_response($message); |
|
337 | + $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) |
|
338 | + ? $PayPalResult['TRANSACTIONID'] |
|
339 | + : null); |
|
340 | + $primary_registration_code = $primary_registrant instanceof EE_Registration |
|
341 | + ? $primary_registrant->reg_code() |
|
342 | + : ''; |
|
343 | + $payment->set_extra_accntng($primary_registration_code); |
|
344 | + $payment->set_details($PayPalResult); |
|
345 | + } |
|
346 | + } catch (Exception $e) { |
|
347 | + $payment->set_status($this->_pay_model->failed_status()); |
|
348 | + $payment->set_gateway_response($e->getMessage()); |
|
349 | + } |
|
350 | + // $payment->set_status( $this->_pay_model->declined_status() ); |
|
351 | + // $payment->set_gateway_response( '' ); |
|
352 | + return $payment; |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * CLeans out sensitive CC data and then logs it, and returns the cleaned request |
|
359 | + * |
|
360 | + * @param array $request |
|
361 | + * @param EEI_Payment $payment |
|
362 | + * @return void |
|
363 | + */ |
|
364 | + private function _log_clean_request($request, $payment) |
|
365 | + { |
|
366 | + $cleaned_request_data = $request; |
|
367 | + unset($cleaned_request_data['CCDetails']['acct']); |
|
368 | + unset($cleaned_request_data['CCDetails']['cvv2']); |
|
369 | + unset($cleaned_request_data['CCDetails']['expdate']); |
|
370 | + $this->log(array('Paypal Request' => $cleaned_request_data), $payment); |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * Cleans the response, logs it, and returns it |
|
377 | + * |
|
378 | + * @param array $response |
|
379 | + * @param EEI_Payment $payment |
|
380 | + * @return array cleaned |
|
381 | + */ |
|
382 | + private function _log_clean_response($response, $payment) |
|
383 | + { |
|
384 | + unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
|
385 | + unset($response['REQUESTDATA']['ACCT']); |
|
386 | + unset($response['REQUESTDATA']['EXPDATE']); |
|
387 | + unset($response['REQUESTDATA']['CVV2']); |
|
388 | + unset($response['RAWREQUEST']); |
|
389 | + $this->log(array('Paypal Response' => $response), $payment); |
|
390 | + return $response; |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + |
|
395 | + /** |
|
396 | + * @param $DataArray |
|
397 | + * @return array |
|
398 | + */ |
|
399 | + private function prep_and_curl_request($DataArray) |
|
400 | + { |
|
401 | + // Create empty holders for each portion of the NVP string |
|
402 | + $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP'; |
|
403 | + $CCDetailsNVP = ''; |
|
404 | + $PayerInfoNVP = ''; |
|
405 | + $PayerNameNVP = ''; |
|
406 | + $BillingAddressNVP = ''; |
|
407 | + $ShippingAddressNVP = ''; |
|
408 | + $PaymentDetailsNVP = ''; |
|
409 | + $OrderItemsNVP = ''; |
|
410 | + $Secure3DNVP = ''; |
|
411 | + // DP Fields |
|
412 | + $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
|
413 | + foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
|
414 | + $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
415 | + } |
|
416 | + // CC Details Fields |
|
417 | + $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
|
418 | + foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
|
419 | + $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
420 | + } |
|
421 | + // PayerInfo Type Fields |
|
422 | + $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
|
423 | + foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
|
424 | + $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
425 | + } |
|
426 | + // Payer Name Fields |
|
427 | + $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
|
428 | + foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
|
429 | + $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
430 | + } |
|
431 | + // Address Fields (Billing) |
|
432 | + $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
|
433 | + foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
|
434 | + $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
435 | + } |
|
436 | + // Payment Details Type Fields |
|
437 | + $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
|
438 | + foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
|
439 | + $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
440 | + } |
|
441 | + // Payment Details Item Type Fields |
|
442 | + $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
|
443 | + $n = 0; |
|
444 | + foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
|
445 | + $CurrentItem = $OrderItems[ $OrderItemsVar ]; |
|
446 | + foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
|
447 | + $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
448 | + } |
|
449 | + $n++; |
|
450 | + } |
|
451 | + // Ship To Address Fields |
|
452 | + $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
|
453 | + foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
|
454 | + $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
455 | + } |
|
456 | + // 3D Secure Fields |
|
457 | + $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
|
458 | + foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
|
459 | + $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
460 | + } |
|
461 | + // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
|
462 | + $NVPRequest = 'USER=' |
|
463 | + . $this->_api_username |
|
464 | + . '&PWD=' |
|
465 | + . $this->_api_password |
|
466 | + . '&VERSION=64.0' |
|
467 | + . '&SIGNATURE=' |
|
468 | + . $this->_api_signature |
|
469 | + . $DPFieldsNVP |
|
470 | + . $CCDetailsNVP |
|
471 | + . $PayerInfoNVP |
|
472 | + . $PayerNameNVP |
|
473 | + . $BillingAddressNVP |
|
474 | + . $PaymentDetailsNVP |
|
475 | + . $OrderItemsNVP |
|
476 | + . $ShippingAddressNVP |
|
477 | + . $Secure3DNVP; |
|
478 | + $NVPResponse = $this->_CURLRequest($NVPRequest); |
|
479 | + $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
|
480 | + $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
|
481 | + $Errors = $this->_GetErrors($NVPResponseArray); |
|
482 | + $NVPResponseArray['ERRORS'] = $Errors; |
|
483 | + $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; |
|
484 | + $NVPResponseArray['RAWREQUEST'] = $NVPRequest; |
|
485 | + $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; |
|
486 | + return $NVPResponseArray; |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * @param $Request |
|
493 | + * @return mixed |
|
494 | + */ |
|
495 | + private function _CURLRequest($Request) |
|
496 | + { |
|
497 | + $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
|
498 | + $curl = curl_init(); |
|
499 | + curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true)); |
|
500 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
501 | + curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
502 | + curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
|
503 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
504 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); |
|
505 | + curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
506 | + // execute the curl POST |
|
507 | + $Response = curl_exec($curl); |
|
508 | + curl_close($curl); |
|
509 | + return $Response; |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * @param $NVPString |
|
516 | + * @return array |
|
517 | + */ |
|
518 | + private function _NVPToArray($NVPString) |
|
519 | + { |
|
520 | + // prepare responses into array |
|
521 | + $proArray = array(); |
|
522 | + while (strlen($NVPString)) { |
|
523 | + // name |
|
524 | + $keypos = strpos($NVPString, '='); |
|
525 | + $keyval = substr($NVPString, 0, $keypos); |
|
526 | + // value |
|
527 | + $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
|
528 | + $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
|
529 | + // decoding the response |
|
530 | + $proArray[ $keyval ] = urldecode($valval); |
|
531 | + $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
|
532 | + } |
|
533 | + return $proArray; |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + |
|
538 | + /** |
|
539 | + * @param array $PayPalResult |
|
540 | + * @return bool |
|
541 | + */ |
|
542 | + private function _APICallSuccessful($PayPalResult) |
|
543 | + { |
|
544 | + $approved = false; |
|
545 | + // check main response message from PayPal |
|
546 | + if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
547 | + $ack = strtoupper($PayPalResult['ACK']); |
|
548 | + $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
549 | + } |
|
550 | + return $approved; |
|
551 | + } |
|
552 | + |
|
553 | + |
|
554 | + |
|
555 | + /** |
|
556 | + * @param $DataArray |
|
557 | + * @return array |
|
558 | + */ |
|
559 | + private function _GetErrors($DataArray) |
|
560 | + { |
|
561 | + $Errors = array(); |
|
562 | + $n = 0; |
|
563 | + while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) { |
|
564 | + $LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : ''; |
|
565 | + $LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ]) |
|
566 | + ? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ] |
|
567 | + : ''; |
|
568 | + $LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ]) |
|
569 | + ? $DataArray[ 'L_LONGMESSAGE' . $n . '' ] |
|
570 | + : ''; |
|
571 | + $LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ]) |
|
572 | + ? $DataArray[ 'L_SEVERITYCODE' . $n . '' ] |
|
573 | + : ''; |
|
574 | + $CurrentItem = array( |
|
575 | + 'L_ERRORCODE' => $LErrorCode, |
|
576 | + 'L_SHORTMESSAGE' => $LShortMessage, |
|
577 | + 'L_LONGMESSAGE' => $LLongMessage, |
|
578 | + 'L_SEVERITYCODE' => $LSeverityCode, |
|
579 | + ); |
|
580 | + array_push($Errors, $CurrentItem); |
|
581 | + $n++; |
|
582 | + } |
|
583 | + return $Errors; |
|
584 | + } |
|
585 | + |
|
586 | + |
|
587 | + |
|
588 | + /** |
|
589 | + * nothing to see here... move along.... |
|
590 | + * |
|
591 | + * @access protected |
|
592 | + * @param $Errors |
|
593 | + * @return string |
|
594 | + */ |
|
595 | + private function _DisplayErrors($Errors) |
|
596 | + { |
|
597 | + $error = ''; |
|
598 | + foreach ($Errors as $ErrorVar => $ErrorVal) { |
|
599 | + $CurrentError = $Errors[ $ErrorVar ]; |
|
600 | + foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
|
601 | + $CurrentVarName = ''; |
|
602 | + if ($CurrentErrorVar == 'L_ERRORCODE') { |
|
603 | + $CurrentVarName = 'Error Code'; |
|
604 | + } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') { |
|
605 | + $CurrentVarName = 'Short Message'; |
|
606 | + } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') { |
|
607 | + $CurrentVarName = 'Long Message'; |
|
608 | + } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
|
609 | + $CurrentVarName = 'Severity Code'; |
|
610 | + } |
|
611 | + $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
612 | + } |
|
613 | + } |
|
614 | + return $error; |
|
615 | + } |
|
616 | 616 | } |
@@ -63,22 +63,22 @@ discard block |
||
63 | 63 | // 'html_id'=> 'ee-Paypal_Pro-billing-form', |
64 | 64 | 'subsections'=>array( |
65 | 65 | 'credit_card'=>new EE_Credit_Card_Input( |
66 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Number', 'event_espresso')) |
|
66 | + array('required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Number', 'event_espresso')) |
|
67 | 67 | ), |
68 | 68 | 'credit_card_type'=>new EE_Select_Input( |
69 | 69 | // the options are set dynamically |
70 | 70 | array_intersect_key(EE_PMT_Paypal_Pro::card_types_supported(), array_flip($allowed_types)), |
71 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Type', 'event_espresso')) |
|
71 | + array('required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Type', 'event_espresso')) |
|
72 | 72 | ), |
73 | 73 | 'exp_month'=>new EE_Credit_Card_Month_Input( |
74 | 74 | true, |
75 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Month', 'event_espresso') ) |
|
75 | + array('required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Month', 'event_espresso')) |
|
76 | 76 | ), |
77 | 77 | 'exp_year'=>new EE_Credit_Card_Year_Input( |
78 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Year', 'event_espresso') ) |
|
78 | + array('required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Year', 'event_espresso')) |
|
79 | 79 | ), |
80 | 80 | 'cvv'=>new EE_CVV_Input( |
81 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('CVV', 'event_espresso') ) |
|
81 | + array('required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('CVV', 'event_espresso')) |
|
82 | 82 | ), |
83 | 83 | ) |
84 | 84 | ) |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | { |
100 | 100 | if ($this->_pm_instance->debug_mode()) { |
101 | 101 | $billing_form->add_subsections( |
102 | - array( 'fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html() ), |
|
102 | + array('fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html()), |
|
103 | 103 | 'credit_card' |
104 | 104 | ); |
105 | 105 | $billing_form->add_subsections( |
106 | - array( 'debug_content' => new EE_Form_Section_HTML_From_Template(dirname(__FILE__).DS.'templates'.DS.'paypal_pro_debug_info.template.php')), |
|
106 | + array('debug_content' => new EE_Form_Section_HTML_From_Template(dirname(__FILE__).DS.'templates'.DS.'paypal_pro_debug_info.template.php')), |
|
107 | 107 | 'first_name' |
108 | 108 | ); |
109 | 109 | $billing_form->get_input('credit_card_type')->set_default('Visa'); |
@@ -184,9 +184,9 @@ discard block |
||
184 | 184 | ] |
185 | 185 | ); |
186 | 186 | // If they existed, set the new ones instead |
187 | - if (!empty($old_extra_metas)) { |
|
187 | + if ( ! empty($old_extra_metas)) { |
|
188 | 188 | foreach ($old_extra_metas as $old_extra_meta) { |
189 | - $old_extra_meta->set('EXM_key', 'api_' . $old_extra_meta->get('EXM_key')); |
|
189 | + $old_extra_meta->set('EXM_key', 'api_'.$old_extra_meta->get('EXM_key')); |
|
190 | 190 | $old_extra_meta->save(); |
191 | 191 | } |
192 | 192 | } |
@@ -14,182 +14,182 @@ |
||
14 | 14 | class EE_PMT_Paypal_Pro extends EE_PMT_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param EE_Payment_Method $pm_instance |
|
19 | - * @return EE_PMT_Paypal_Pro |
|
20 | - */ |
|
21 | - public function __construct($pm_instance = null) |
|
22 | - { |
|
23 | - require_once($this->file_folder().'EEG_Paypal_Pro.gateway.php'); |
|
24 | - $this->_gateway = new EEG_Paypal_Pro(); |
|
25 | - $this->_pretty_name = __("Paypal Pro", 'event_espresso'); |
|
26 | - $this->_default_description = __('Please provide the following billing information.', 'event_espresso'); |
|
27 | - $this->_requires_https = true; |
|
28 | - parent::__construct($pm_instance); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * Gets the form for all the settings related to this payment method type |
|
34 | - * @return EE_Payment_Method_Form |
|
35 | - * @throws InvalidArgumentException |
|
36 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
37 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
38 | - */ |
|
39 | - public function generate_new_settings_form() |
|
40 | - { |
|
41 | - return new PayPalProSettingsForm(array(), $this->get_help_tab_link()); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * Creates the billing form for this payment method type |
|
47 | - * @param \EE_Transaction $transaction |
|
48 | - * @throws \EE_Error |
|
49 | - * @return EE_Billing_Info_Form |
|
50 | - */ |
|
51 | - public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
52 | - { |
|
53 | - $allowed_types = $this->_pm_instance->get_extra_meta('credit_card_types', true); |
|
54 | - // if allowed types is a string or empty array or null... |
|
55 | - if (empty($allowed_types)) { |
|
56 | - $allowed_types = array(); |
|
57 | - } |
|
58 | - |
|
59 | - $billing_form = new EE_Billing_Attendee_Info_Form( |
|
60 | - $this->_pm_instance, |
|
61 | - array( |
|
62 | - 'name'=> 'Paypal_Pro_Billing_Form', |
|
63 | - // 'html_id'=> 'ee-Paypal_Pro-billing-form', |
|
64 | - 'subsections'=>array( |
|
65 | - 'credit_card'=>new EE_Credit_Card_Input( |
|
66 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Number', 'event_espresso')) |
|
67 | - ), |
|
68 | - 'credit_card_type'=>new EE_Select_Input( |
|
69 | - // the options are set dynamically |
|
70 | - array_intersect_key(EE_PMT_Paypal_Pro::card_types_supported(), array_flip($allowed_types)), |
|
71 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Type', 'event_espresso')) |
|
72 | - ), |
|
73 | - 'exp_month'=>new EE_Credit_Card_Month_Input( |
|
74 | - true, |
|
75 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Month', 'event_espresso') ) |
|
76 | - ), |
|
77 | - 'exp_year'=>new EE_Credit_Card_Year_Input( |
|
78 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Year', 'event_espresso') ) |
|
79 | - ), |
|
80 | - 'cvv'=>new EE_CVV_Input( |
|
81 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('CVV', 'event_espresso') ) |
|
82 | - ), |
|
83 | - ) |
|
84 | - ) |
|
85 | - ); |
|
86 | - return $this->apply_billing_form_debug_settings($billing_form); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * apply_billing_form_debug_settings |
|
93 | - * applies debug data to the form |
|
94 | - * |
|
95 | - * @param \EE_Billing_Info_Form $billing_form |
|
96 | - * @return \EE_Billing_Info_Form |
|
97 | - */ |
|
98 | - public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) |
|
99 | - { |
|
100 | - if ($this->_pm_instance->debug_mode()) { |
|
101 | - $billing_form->add_subsections( |
|
102 | - array( 'fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html() ), |
|
103 | - 'credit_card' |
|
104 | - ); |
|
105 | - $billing_form->add_subsections( |
|
106 | - array( 'debug_content' => new EE_Form_Section_HTML_From_Template(dirname(__FILE__).DS.'templates'.DS.'paypal_pro_debug_info.template.php')), |
|
107 | - 'first_name' |
|
108 | - ); |
|
109 | - $billing_form->get_input('credit_card_type')->set_default('Visa'); |
|
110 | - $billing_form->get_input('exp_year')->set_default(2018); |
|
111 | - $billing_form->get_input('cvv')->set_default('115'); |
|
112 | - } |
|
113 | - return $billing_form; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * Returns an array of all the payment cards possibly supported by paypal pro. |
|
120 | - * Keys are their values, values are their pretty names. |
|
121 | - * @return array |
|
122 | - */ |
|
123 | - public static function card_types_supported() |
|
124 | - { |
|
125 | - return array( |
|
126 | - 'Visa'=> __("Visa", 'event_espresso'), |
|
127 | - 'MasterCard'=> __("MasterCard", 'event_espresso'), |
|
128 | - 'Amex'=> __("American Express", 'event_espresso'), |
|
129 | - 'Discover'=> __("Discover", 'event_espresso') |
|
130 | - ); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * Adds the help tab |
|
137 | - * @see EE_PMT_Base::help_tabs_config() |
|
138 | - * @return array |
|
139 | - */ |
|
140 | - public function help_tabs_config() |
|
141 | - { |
|
142 | - return array( |
|
143 | - $this->get_help_tab_name() => array( |
|
144 | - 'title' => __('PayPal Pro Settings', 'event_espresso'), |
|
145 | - 'filename' => 'payment_methods_overview_paypalpro' |
|
146 | - ), |
|
147 | - ); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Overrides parent's _get_billing_values_from_form because we want to |
|
152 | - * get the country's 2-character ISO code, not the name like most gateways |
|
153 | - * @param EE_Billing_Info_Form $billing_form |
|
154 | - * @return array |
|
155 | - */ |
|
156 | - protected function _get_billing_values_from_form($billing_form) |
|
157 | - { |
|
158 | - $billing_values = parent::_get_billing_values_from_form($billing_form); |
|
159 | - $billing_values['country'] = $billing_form->get_input_value('country'); |
|
160 | - $billing_values['credit_card_type'] = $billing_form->get_input_value('credit_card_type'); |
|
161 | - return $billing_values; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Override parent to account for a change in extra meta inputs in 4.9.75.p |
|
166 | - * @since 4.9.79.p |
|
167 | - * @param EE_Payment_Method $payment_method_instance |
|
168 | - * @throws EE_Error |
|
169 | - * @throws InvalidArgumentException |
|
170 | - * @throws ReflectionException |
|
171 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
172 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
173 | - */ |
|
174 | - public function set_instance($payment_method_instance) |
|
175 | - { |
|
176 | - // Check for the old extra meta inputs |
|
177 | - $old_extra_metas = EEM_Extra_Meta::instance()->get_all( |
|
178 | - [ |
|
179 | - [ |
|
180 | - 'EXM_type' => 'Payment_Method', |
|
181 | - 'OBJ_ID' => $payment_method_instance->ID(), |
|
182 | - 'EXM_key' => ['IN', ['username', 'password', 'signature']], |
|
183 | - ] |
|
184 | - ] |
|
185 | - ); |
|
186 | - // If they existed, set the new ones instead |
|
187 | - if (!empty($old_extra_metas)) { |
|
188 | - foreach ($old_extra_metas as $old_extra_meta) { |
|
189 | - $old_extra_meta->set('EXM_key', 'api_' . $old_extra_meta->get('EXM_key')); |
|
190 | - $old_extra_meta->save(); |
|
191 | - } |
|
192 | - } |
|
193 | - return parent::set_instance($payment_method_instance); |
|
194 | - } |
|
17 | + /** |
|
18 | + * @param EE_Payment_Method $pm_instance |
|
19 | + * @return EE_PMT_Paypal_Pro |
|
20 | + */ |
|
21 | + public function __construct($pm_instance = null) |
|
22 | + { |
|
23 | + require_once($this->file_folder().'EEG_Paypal_Pro.gateway.php'); |
|
24 | + $this->_gateway = new EEG_Paypal_Pro(); |
|
25 | + $this->_pretty_name = __("Paypal Pro", 'event_espresso'); |
|
26 | + $this->_default_description = __('Please provide the following billing information.', 'event_espresso'); |
|
27 | + $this->_requires_https = true; |
|
28 | + parent::__construct($pm_instance); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * Gets the form for all the settings related to this payment method type |
|
34 | + * @return EE_Payment_Method_Form |
|
35 | + * @throws InvalidArgumentException |
|
36 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
37 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
38 | + */ |
|
39 | + public function generate_new_settings_form() |
|
40 | + { |
|
41 | + return new PayPalProSettingsForm(array(), $this->get_help_tab_link()); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * Creates the billing form for this payment method type |
|
47 | + * @param \EE_Transaction $transaction |
|
48 | + * @throws \EE_Error |
|
49 | + * @return EE_Billing_Info_Form |
|
50 | + */ |
|
51 | + public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
52 | + { |
|
53 | + $allowed_types = $this->_pm_instance->get_extra_meta('credit_card_types', true); |
|
54 | + // if allowed types is a string or empty array or null... |
|
55 | + if (empty($allowed_types)) { |
|
56 | + $allowed_types = array(); |
|
57 | + } |
|
58 | + |
|
59 | + $billing_form = new EE_Billing_Attendee_Info_Form( |
|
60 | + $this->_pm_instance, |
|
61 | + array( |
|
62 | + 'name'=> 'Paypal_Pro_Billing_Form', |
|
63 | + // 'html_id'=> 'ee-Paypal_Pro-billing-form', |
|
64 | + 'subsections'=>array( |
|
65 | + 'credit_card'=>new EE_Credit_Card_Input( |
|
66 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Number', 'event_espresso')) |
|
67 | + ), |
|
68 | + 'credit_card_type'=>new EE_Select_Input( |
|
69 | + // the options are set dynamically |
|
70 | + array_intersect_key(EE_PMT_Paypal_Pro::card_types_supported(), array_flip($allowed_types)), |
|
71 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Type', 'event_espresso')) |
|
72 | + ), |
|
73 | + 'exp_month'=>new EE_Credit_Card_Month_Input( |
|
74 | + true, |
|
75 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Month', 'event_espresso') ) |
|
76 | + ), |
|
77 | + 'exp_year'=>new EE_Credit_Card_Year_Input( |
|
78 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Year', 'event_espresso') ) |
|
79 | + ), |
|
80 | + 'cvv'=>new EE_CVV_Input( |
|
81 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('CVV', 'event_espresso') ) |
|
82 | + ), |
|
83 | + ) |
|
84 | + ) |
|
85 | + ); |
|
86 | + return $this->apply_billing_form_debug_settings($billing_form); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * apply_billing_form_debug_settings |
|
93 | + * applies debug data to the form |
|
94 | + * |
|
95 | + * @param \EE_Billing_Info_Form $billing_form |
|
96 | + * @return \EE_Billing_Info_Form |
|
97 | + */ |
|
98 | + public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) |
|
99 | + { |
|
100 | + if ($this->_pm_instance->debug_mode()) { |
|
101 | + $billing_form->add_subsections( |
|
102 | + array( 'fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html() ), |
|
103 | + 'credit_card' |
|
104 | + ); |
|
105 | + $billing_form->add_subsections( |
|
106 | + array( 'debug_content' => new EE_Form_Section_HTML_From_Template(dirname(__FILE__).DS.'templates'.DS.'paypal_pro_debug_info.template.php')), |
|
107 | + 'first_name' |
|
108 | + ); |
|
109 | + $billing_form->get_input('credit_card_type')->set_default('Visa'); |
|
110 | + $billing_form->get_input('exp_year')->set_default(2018); |
|
111 | + $billing_form->get_input('cvv')->set_default('115'); |
|
112 | + } |
|
113 | + return $billing_form; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * Returns an array of all the payment cards possibly supported by paypal pro. |
|
120 | + * Keys are their values, values are their pretty names. |
|
121 | + * @return array |
|
122 | + */ |
|
123 | + public static function card_types_supported() |
|
124 | + { |
|
125 | + return array( |
|
126 | + 'Visa'=> __("Visa", 'event_espresso'), |
|
127 | + 'MasterCard'=> __("MasterCard", 'event_espresso'), |
|
128 | + 'Amex'=> __("American Express", 'event_espresso'), |
|
129 | + 'Discover'=> __("Discover", 'event_espresso') |
|
130 | + ); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * Adds the help tab |
|
137 | + * @see EE_PMT_Base::help_tabs_config() |
|
138 | + * @return array |
|
139 | + */ |
|
140 | + public function help_tabs_config() |
|
141 | + { |
|
142 | + return array( |
|
143 | + $this->get_help_tab_name() => array( |
|
144 | + 'title' => __('PayPal Pro Settings', 'event_espresso'), |
|
145 | + 'filename' => 'payment_methods_overview_paypalpro' |
|
146 | + ), |
|
147 | + ); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Overrides parent's _get_billing_values_from_form because we want to |
|
152 | + * get the country's 2-character ISO code, not the name like most gateways |
|
153 | + * @param EE_Billing_Info_Form $billing_form |
|
154 | + * @return array |
|
155 | + */ |
|
156 | + protected function _get_billing_values_from_form($billing_form) |
|
157 | + { |
|
158 | + $billing_values = parent::_get_billing_values_from_form($billing_form); |
|
159 | + $billing_values['country'] = $billing_form->get_input_value('country'); |
|
160 | + $billing_values['credit_card_type'] = $billing_form->get_input_value('credit_card_type'); |
|
161 | + return $billing_values; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Override parent to account for a change in extra meta inputs in 4.9.75.p |
|
166 | + * @since 4.9.79.p |
|
167 | + * @param EE_Payment_Method $payment_method_instance |
|
168 | + * @throws EE_Error |
|
169 | + * @throws InvalidArgumentException |
|
170 | + * @throws ReflectionException |
|
171 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
172 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
173 | + */ |
|
174 | + public function set_instance($payment_method_instance) |
|
175 | + { |
|
176 | + // Check for the old extra meta inputs |
|
177 | + $old_extra_metas = EEM_Extra_Meta::instance()->get_all( |
|
178 | + [ |
|
179 | + [ |
|
180 | + 'EXM_type' => 'Payment_Method', |
|
181 | + 'OBJ_ID' => $payment_method_instance->ID(), |
|
182 | + 'EXM_key' => ['IN', ['username', 'password', 'signature']], |
|
183 | + ] |
|
184 | + ] |
|
185 | + ); |
|
186 | + // If they existed, set the new ones instead |
|
187 | + if (!empty($old_extra_metas)) { |
|
188 | + foreach ($old_extra_metas as $old_extra_meta) { |
|
189 | + $old_extra_meta->set('EXM_key', 'api_' . $old_extra_meta->get('EXM_key')); |
|
190 | + $old_extra_meta->save(); |
|
191 | + } |
|
192 | + } |
|
193 | + return parent::set_instance($payment_method_instance); |
|
194 | + } |
|
195 | 195 | } |
@@ -10,19 +10,19 @@ discard block |
||
10 | 10 | ?> |
11 | 11 | <div id="admin-side-mbox-primary-registrant-dv" class="admin-side-mbox-dv"> |
12 | 12 | <?php |
13 | - if (! empty($no_attendee_message)) : ?> |
|
13 | + if (! empty($no_attendee_message)) : ?> |
|
14 | 14 | <p class="clearfix"> |
15 | 15 | <?php echo $no_attendee_message; ?> |
16 | 16 | </p> |
17 | 17 | </div> <!-- end #admin-side-mbox-primary-registrant-dv --> |
18 | 18 | <?php |
19 | - else : ?> |
|
19 | + else : ?> |
|
20 | 20 | <p class="clearfix"> |
21 | 21 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"> |
22 | 22 | <?php esc_html_e( |
23 | - 'Name', |
|
24 | - 'event_espresso' |
|
25 | - ); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?> |
|
23 | + 'Name', |
|
24 | + 'event_espresso' |
|
25 | + ); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?> |
|
26 | 26 | </p> |
27 | 27 | <p class="clearfix"> |
28 | 28 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php esc_html_e('Email', 'event_espresso'); ?></span><a |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | <p class="clearfix"> |
32 | 32 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"> |
33 | 33 | <?php esc_html_e( |
34 | - 'Phone #', |
|
35 | - 'event_espresso' |
|
36 | - ); ?> |
|
34 | + 'Phone #', |
|
35 | + 'event_espresso' |
|
36 | + ); ?> |
|
37 | 37 | </span> |
38 | 38 | <?php if (! empty($prime_reg_phone)) : ?> |
39 | 39 | <a href="tel:<?php echo $phone; ?>"> |
@@ -50,22 +50,22 @@ discard block |
||
50 | 50 | </div> <!-- end #admin-side-mbox-primary-registrant-dv --> |
51 | 51 | |
52 | 52 | <?php |
53 | - /** only show if logged in user has access */ |
|
54 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
55 | - 'ee_edit_contact', |
|
56 | - 'view_or_edit_contact_button', |
|
57 | - $ATT_ID |
|
58 | - ) |
|
59 | - ) : ?> |
|
53 | + /** only show if logged in user has access */ |
|
54 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
55 | + 'ee_edit_contact', |
|
56 | + 'view_or_edit_contact_button', |
|
57 | + $ATT_ID |
|
58 | + ) |
|
59 | + ) : ?> |
|
60 | 60 | <p style="text-align:right;"> |
61 | 61 | <a class="button button-small" href="<?php echo $edit_attendee_url; ?>" |
62 | 62 | title="<?php esc_attr_e('View details for this contact.', 'event_espresso'); ?>"> |
63 | 63 | <span class="ee-icon ee-icon-user-edit"></span> |
64 | 64 | <?php _e( |
65 | - 'View / Edit this Contact', |
|
66 | - 'event_espresso' |
|
67 | - ); ?> |
|
65 | + 'View / Edit this Contact', |
|
66 | + 'event_espresso' |
|
67 | + ); ?> |
|
68 | 68 | </a> |
69 | 69 | </p> |
70 | 70 | <?php endif; |
71 | - endif; |
|
71 | + endif; |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | ?> |
11 | 11 | <div id="admin-side-mbox-primary-registrant-dv" class="admin-side-mbox-dv"> |
12 | 12 | <?php |
13 | - if (! empty($no_attendee_message)) : ?> |
|
13 | + if ( ! empty($no_attendee_message)) : ?> |
|
14 | 14 | <p class="clearfix"> |
15 | 15 | <?php echo $no_attendee_message; ?> |
16 | 16 | </p> |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | <?php esc_html_e( |
23 | 23 | 'Name', |
24 | 24 | 'event_espresso' |
25 | - ); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?> |
|
25 | + ); ?></span><?php echo $prime_reg_fname.' '.$prime_reg_lname; ?> |
|
26 | 26 | </p> |
27 | 27 | <p class="clearfix"> |
28 | 28 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php esc_html_e('Email', 'event_espresso'); ?></span><a |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | 'event_espresso' |
36 | 36 | ); ?> |
37 | 37 | </span> |
38 | - <?php if (! empty($prime_reg_phone)) : ?> |
|
38 | + <?php if ( ! empty($prime_reg_phone)) : ?> |
|
39 | 39 | <a href="tel:<?php echo $phone; ?>"> |
40 | 40 | <?php echo $prime_reg_phone; ?> |
41 | 41 | </a> |
@@ -16,13 +16,16 @@ |
||
16 | 16 | </p> |
17 | 17 | </div> <!-- end #admin-side-mbox-primary-registrant-dv --> |
18 | 18 | <?php |
19 | - else : ?> |
|
19 | + else { |
|
20 | + : ?> |
|
20 | 21 | <p class="clearfix"> |
21 | 22 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"> |
22 | 23 | <?php esc_html_e( |
23 | 24 | 'Name', |
24 | 25 | 'event_espresso' |
25 | - ); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?> |
|
26 | + ); |
|
27 | + } |
|
28 | + ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?> |
|
26 | 29 | </p> |
27 | 30 | <p class="clearfix"> |
28 | 31 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php esc_html_e('Email', 'event_espresso'); ?></span><a |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | <p class="clearfix"> |
3 | 3 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"> |
4 | 4 | <?php esc_html_e('Name', 'event_espresso'); ?> |
5 | - </span><?php echo $fname . ' ' . $lname; ?> |
|
5 | + </span><?php echo $fname.' '.$lname; ?> |
|
6 | 6 | </p> |
7 | 7 | <p class="clearfix"> |
8 | 8 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"> |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"> |
17 | 17 | <?php esc_html_e('Phone #', 'event_espresso'); ?> |
18 | 18 | </span> |
19 | - <?php if (! empty($phone)) : ?> |
|
19 | + <?php if ( ! empty($phone)) : ?> |
|
20 | 20 | <a href="tel:<?php echo $phone; ?>"> |
21 | 21 | <?php echo $phone; ?> |
22 | 22 | </a> |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | title="<?php echo esc_attr($att_edit_label); ?>"> |
47 | 47 | <span class="ee-icon ee-icon-user-edit"></span><?php echo $att_edit_label; ?> |
48 | 48 | </a> |
49 | - <?php if (! empty($create_link)) : ?> |
|
49 | + <?php if ( ! empty($create_link)) : ?> |
|
50 | 50 | <a class="button button-small" href="<?php echo $create_link; ?>" |
51 | 51 | title="<?php |
52 | 52 | esc_attr_e( |
@@ -11,42 +11,42 @@ |
||
11 | 11 | class EE_CVV_Input extends EE_Text_Input |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @param array $input_settings { |
|
16 | - * @type boolean $include_whats_this_link defaults to true |
|
17 | - * } |
|
18 | - */ |
|
19 | - public function __construct($input_settings = array()) |
|
20 | - { |
|
21 | - $this->set_sensitive_data_removal_strategy(new EE_CCV_Sensitive_Data_Removal()); |
|
22 | - $this->_add_validation_strategy( |
|
23 | - new EE_Text_Validation_Strategy( |
|
24 | - isset($input_settings['validation_error_message']) |
|
25 | - ? $input_settings['validation_error_message'] |
|
26 | - : esc_html__( |
|
27 | - 'The CVV is either a 3 digit number on the back of your card, or 4 digit number on the front', |
|
28 | - 'event_espresso' |
|
29 | - ), |
|
30 | - '~^\d{3,4}$~' |
|
31 | - ) |
|
32 | - ); |
|
33 | - parent::__construct($input_settings); |
|
34 | - if (! isset($input_settings['include_whats_this_link']) |
|
35 | - || ( |
|
36 | - isset($input_settings['include_whats_this_link']) |
|
37 | - && $input_settings['include_whats_this_link'] === true |
|
38 | - ) |
|
39 | - ) { |
|
40 | - $this->_html_label_text = sprintf( |
|
41 | - esc_html_x( |
|
42 | - '%1$s %2$s(What\'s this?)%3$s', |
|
43 | - 'CVV (What\'s this?)', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - $this->_html_label_text, |
|
47 | - '<a href="https://www.cvvnumber.com/" target="_blank" rel="noopener noreferrer">', |
|
48 | - '</a>' |
|
49 | - ); |
|
50 | - } |
|
51 | - } |
|
14 | + /** |
|
15 | + * @param array $input_settings { |
|
16 | + * @type boolean $include_whats_this_link defaults to true |
|
17 | + * } |
|
18 | + */ |
|
19 | + public function __construct($input_settings = array()) |
|
20 | + { |
|
21 | + $this->set_sensitive_data_removal_strategy(new EE_CCV_Sensitive_Data_Removal()); |
|
22 | + $this->_add_validation_strategy( |
|
23 | + new EE_Text_Validation_Strategy( |
|
24 | + isset($input_settings['validation_error_message']) |
|
25 | + ? $input_settings['validation_error_message'] |
|
26 | + : esc_html__( |
|
27 | + 'The CVV is either a 3 digit number on the back of your card, or 4 digit number on the front', |
|
28 | + 'event_espresso' |
|
29 | + ), |
|
30 | + '~^\d{3,4}$~' |
|
31 | + ) |
|
32 | + ); |
|
33 | + parent::__construct($input_settings); |
|
34 | + if (! isset($input_settings['include_whats_this_link']) |
|
35 | + || ( |
|
36 | + isset($input_settings['include_whats_this_link']) |
|
37 | + && $input_settings['include_whats_this_link'] === true |
|
38 | + ) |
|
39 | + ) { |
|
40 | + $this->_html_label_text = sprintf( |
|
41 | + esc_html_x( |
|
42 | + '%1$s %2$s(What\'s this?)%3$s', |
|
43 | + 'CVV (What\'s this?)', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + $this->_html_label_text, |
|
47 | + '<a href="https://www.cvvnumber.com/" target="_blank" rel="noopener noreferrer">', |
|
48 | + '</a>' |
|
49 | + ); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | $this->_add_validation_strategy( |
23 | 23 | new EE_Text_Validation_Strategy( |
24 | 24 | isset($input_settings['validation_error_message']) |
25 | - ? $input_settings['validation_error_message'] |
|
25 | + ? $input_settings['validation_error_message'] |
|
26 | 26 | : esc_html__( |
27 | 27 | 'The CVV is either a 3 digit number on the back of your card, or 4 digit number on the front', |
28 | 28 | 'event_espresso' |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | ) |
32 | 32 | ); |
33 | 33 | parent::__construct($input_settings); |
34 | - if (! isset($input_settings['include_whats_this_link']) |
|
34 | + if ( ! isset($input_settings['include_whats_this_link']) |
|
35 | 35 | || ( |
36 | 36 | isset($input_settings['include_whats_this_link']) |
37 | 37 | && $input_settings['include_whats_this_link'] === true |