@@ -1,91 +1,91 @@ |
||
1 | 1 | <div id="ee-single-page-checkout-dv" class=""> |
2 | 2 | <?php |
3 | - if (! $empty_cart) { |
|
4 | - if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) { ?> |
|
3 | + if (! $empty_cart) { |
|
4 | + if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) { ?> |
|
5 | 5 | <p id="spco-registration-time-limit-pg" class="spco-steps-pg ee-attention important-notice" |
6 | 6 | style="display: none;"> |
7 | 7 | <?php echo sprintf( |
8 | - apply_filters( |
|
9 | - 'FHEE__registration_page_wrapper_template___time_limit', |
|
10 | - __('You have %1$s to complete your registration.', 'event_espresso') |
|
11 | - ), |
|
12 | - '<span id="spco-registration-time-limit-spn" class="spco-registration-time-limit-spn">' . $registration_time_limit . '</span>' |
|
13 | - ); |
|
14 | - ?> |
|
8 | + apply_filters( |
|
9 | + 'FHEE__registration_page_wrapper_template___time_limit', |
|
10 | + __('You have %1$s to complete your registration.', 'event_espresso') |
|
11 | + ), |
|
12 | + '<span id="spco-registration-time-limit-spn" class="spco-registration-time-limit-spn">' . $registration_time_limit . '</span>' |
|
13 | + ); |
|
14 | + ?> |
|
15 | 15 | <span id="spco-registration-expiration-spn" class="" style="display:none;"></span> |
16 | 16 | </p> |
17 | 17 | <?php } |
18 | - if (! $revisit && apply_filters('FHEE__registration_page_wrapper_template__steps_display', true)) { |
|
19 | - ?> |
|
18 | + if (! $revisit && apply_filters('FHEE__registration_page_wrapper_template__steps_display', true)) { |
|
19 | + ?> |
|
20 | 20 | <h2 id="spco-steps-big-hdr" class="spco-steps-big-hdr"><?php _e(' Steps', 'event_espresso'); ?></h2> |
21 | 21 | |
22 | 22 | <div id="spco-steps-display-dv"> |
23 | 23 | <?php |
24 | - $step_nmbr = 1; |
|
25 | - $total_steps = count($reg_steps) - 1; |
|
26 | - foreach ($reg_steps as $reg_step) { |
|
27 | - if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
28 | - $slug = $reg_step->slug(); |
|
29 | - $step_display_dv_class = $reg_step->is_current_step() ? 'active-step' : 'inactive-step'; |
|
30 | - ?> |
|
24 | + $step_nmbr = 1; |
|
25 | + $total_steps = count($reg_steps) - 1; |
|
26 | + foreach ($reg_steps as $reg_step) { |
|
27 | + if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
28 | + $slug = $reg_step->slug(); |
|
29 | + $step_display_dv_class = $reg_step->is_current_step() ? 'active-step' : 'inactive-step'; |
|
30 | + ?> |
|
31 | 31 | <div id="spco-step-<?php echo $slug; ?>-display-dv" |
32 | 32 | class="spco-step-display-dv <?php echo $step_display_dv_class; ?> steps-<?php echo $total_steps; ?>"> |
33 | 33 | <h4 id="spco-step-<?php echo $slug; ?>-display-hdr" class="spco-steps-display-hdr"> |
34 | 34 | <span class="spco-step-big-nmbr"><?php echo $step_nmbr; ?></span> |
35 | 35 | <span class="spco-step-name"> |
36 | 36 | <?php echo str_replace( |
37 | - ' ', |
|
38 | - '<br/> ', |
|
39 | - $reg_step->name() |
|
40 | - ); ?> |
|
37 | + ' ', |
|
38 | + '<br/> ', |
|
39 | + $reg_step->name() |
|
40 | + ); ?> |
|
41 | 41 | </span> |
42 | 42 | </h4> |
43 | 43 | </div> |
44 | 44 | |
45 | 45 | <?php |
46 | - if ($step_nmbr < $total_steps) { ?> |
|
46 | + if ($step_nmbr < $total_steps) { ?> |
|
47 | 47 | <div class="spco-step-arrow-dv">»</div> |
48 | 48 | <?php |
49 | - } |
|
50 | - $step_nmbr++; |
|
51 | - } |
|
52 | - } |
|
53 | - ?> |
|
49 | + } |
|
50 | + $step_nmbr++; |
|
51 | + } |
|
52 | + } |
|
53 | + ?> |
|
54 | 54 | <div class="clear-float"></div> |
55 | 55 | </div> |
56 | 56 | |
57 | 57 | <?php |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - do_action('AHEE__SPCO__before_registration_steps'); |
|
61 | - $step_nmbr = 1; |
|
62 | - foreach ($reg_steps as $reg_step) { |
|
63 | - if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
64 | - $slug = $reg_step->slug(); |
|
65 | - do_action('AHEE__' . $slug . '__reg_step_start', $reg_step); |
|
66 | - // todo: deprecate hook AHEE__registration_page_attendee_information__start |
|
67 | - ?> |
|
60 | + do_action('AHEE__SPCO__before_registration_steps'); |
|
61 | + $step_nmbr = 1; |
|
62 | + foreach ($reg_steps as $reg_step) { |
|
63 | + if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
64 | + $slug = $reg_step->slug(); |
|
65 | + do_action('AHEE__' . $slug . '__reg_step_start', $reg_step); |
|
66 | + // todo: deprecate hook AHEE__registration_page_attendee_information__start |
|
67 | + ?> |
|
68 | 68 | <div id="spco-<?php echo $slug; ?>-dv" class="spco-step-dv <?php echo $reg_step->div_class(); ?>"> |
69 | 69 | <?php echo $reg_step->display_reg_form(); ?> |
70 | 70 | <?php do_action('AHEE__SPCO_after_reg_step_form', $slug, $next_step); ?> |
71 | 71 | </div> |
72 | 72 | <?php $step_nmbr++; |
73 | - } |
|
74 | - } |
|
75 | - do_action('AHEE__SPCO__after_registration_steps'); |
|
76 | - } else { |
|
77 | - ?> |
|
73 | + } |
|
74 | + } |
|
75 | + do_action('AHEE__SPCO__after_registration_steps'); |
|
76 | + } else { |
|
77 | + ?> |
|
78 | 78 | <h3 id="spco-empty-cart-hdr" class="spco-step-title-hdr"> |
79 | 79 | <?php esc_html_e( |
80 | - 'Nothing in your Event Queue', |
|
81 | - 'event_espresso' |
|
82 | - ); ?></h3> |
|
80 | + 'Nothing in your Event Queue', |
|
81 | + 'event_espresso' |
|
82 | + ); ?></h3> |
|
83 | 83 | <p><?php echo $empty_msg; ?></p> |
84 | 84 | <?php echo $cookies_not_set_msg; ?> |
85 | 85 | <?php |
86 | - } |
|
87 | - do_action('AHEE__SPCO__reg_form_footer'); |
|
88 | - ?> |
|
86 | + } |
|
87 | + do_action('AHEE__SPCO__reg_form_footer'); |
|
88 | + ?> |
|
89 | 89 | |
90 | 90 | </div> |
91 | 91 |
@@ -18,360 +18,360 @@ |
||
18 | 18 | class TicketSelectorRowStandard extends TicketSelectorRow |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var TicketDetails $ticket_details |
|
23 | - */ |
|
24 | - protected $ticket_details; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var \EE_Ticket_Selector_Config $template_settings |
|
28 | - */ |
|
29 | - protected $template_settings; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var EE_Tax_Config $tax_settings |
|
33 | - */ |
|
34 | - protected $tax_settings; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var boolean $prices_displayed_including_taxes |
|
38 | - */ |
|
39 | - protected $prices_displayed_including_taxes; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var int $row |
|
43 | - */ |
|
44 | - protected $row; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var int $cols |
|
48 | - */ |
|
49 | - protected $cols; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var boolean $hidden_input_qty |
|
53 | - */ |
|
54 | - protected $hidden_input_qty; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var string $ticket_datetime_classes |
|
58 | - */ |
|
59 | - protected $ticket_datetime_classes; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * TicketDetails constructor. |
|
64 | - * |
|
65 | - * @param TicketDetails $ticket_details |
|
66 | - * @param EE_Tax_Config $tax_settings |
|
67 | - * @param int $total_tickets |
|
68 | - * @param int $max_attendees |
|
69 | - * @param int $row |
|
70 | - * @param int $cols |
|
71 | - * @param boolean $required_ticket_sold_out |
|
72 | - * @param string $event_status |
|
73 | - * @param string $ticket_datetime_classes |
|
74 | - * @throws EE_Error |
|
75 | - * @throws UnexpectedEntityException |
|
76 | - */ |
|
77 | - public function __construct( |
|
78 | - TicketDetails $ticket_details, |
|
79 | - EE_Tax_Config $tax_settings, |
|
80 | - $total_tickets, |
|
81 | - $max_attendees, |
|
82 | - $row, |
|
83 | - $cols, |
|
84 | - $required_ticket_sold_out, |
|
85 | - $event_status, |
|
86 | - $ticket_datetime_classes |
|
87 | - ) { |
|
88 | - $this->ticket_details = $ticket_details; |
|
89 | - $this->template_settings = $ticket_details->getTemplateSettings(); |
|
90 | - $this->tax_settings = $tax_settings; |
|
91 | - $this->row = $row; |
|
92 | - $this->cols = $cols; |
|
93 | - $this->ticket_datetime_classes = $ticket_datetime_classes; |
|
94 | - parent::__construct( |
|
95 | - $ticket_details->getTicket(), |
|
96 | - $max_attendees, |
|
97 | - $ticket_details->getDateFormat(), |
|
98 | - $event_status, |
|
99 | - $required_ticket_sold_out, |
|
100 | - $total_tickets |
|
101 | - ); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * other ticket rows will need to know if a required ticket is sold out, |
|
107 | - * so that they are not offered for sale |
|
108 | - * |
|
109 | - * @return boolean |
|
110 | - */ |
|
111 | - public function getRequiredTicketSoldOut() |
|
112 | - { |
|
113 | - return $this->required_ticket_sold_out; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @return int |
|
119 | - */ |
|
120 | - public function getCols() |
|
121 | - { |
|
122 | - return $this->cols; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * getHtml |
|
128 | - * |
|
129 | - * @return string |
|
130 | - * @throws EE_Error |
|
131 | - */ |
|
132 | - public function getHtml() |
|
133 | - { |
|
134 | - $this->min = 0; |
|
135 | - $this->max = $this->ticket->max(); |
|
136 | - $remaining = $this->ticket->remaining(); |
|
137 | - $this->setTicketMinAndMax($remaining); |
|
138 | - // set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
|
139 | - $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
|
140 | - ? $this->ticket->start_date() |
|
141 | - : $this->required_ticket_sold_out; |
|
142 | - $this->setTicketPriceDetails(); |
|
143 | - $this->setTicketStatusClasses($remaining); |
|
144 | - $filtered_row_html = $this->getFilteredRowHtml(); |
|
145 | - if ($filtered_row_html !== false) { |
|
146 | - return $filtered_row_html; |
|
147 | - } |
|
148 | - $ticket_selector_row_html = EEH_HTML::tr( |
|
149 | - '', |
|
150 | - '', |
|
151 | - "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " |
|
152 | - . espresso_get_object_css_class($this->ticket) |
|
153 | - ); |
|
154 | - $filtered_row_content = $this->getFilteredRowContents(); |
|
155 | - if ($filtered_row_content !== false && $this->max_attendees === 1) { |
|
156 | - return $ticket_selector_row_html |
|
157 | - . $filtered_row_content |
|
158 | - . $this->ticketQtyAndIdHiddenInputs() |
|
159 | - . EEH_HTML::trx(); |
|
160 | - } |
|
161 | - if ($filtered_row_content !== false) { |
|
162 | - return $ticket_selector_row_html |
|
163 | - . $filtered_row_content |
|
164 | - . EEH_HTML::trx(); |
|
165 | - } |
|
166 | - $this->hidden_input_qty = $this->max_attendees > 1; |
|
167 | - |
|
168 | - $ticket_selector_row_html .= $this->ticketNameTableCell(); |
|
169 | - $ticket_selector_row_html .= $this->ticketPriceTableCell(); |
|
170 | - $ticket_selector_row_html .= EEH_HTML::td( |
|
171 | - '', |
|
172 | - '', |
|
173 | - 'tckt-slctr-tbl-td-qty cntr', |
|
174 | - '', |
|
175 | - 'headers="quantity-' . $this->EVT_ID . '"' |
|
176 | - ); |
|
177 | - $this->setTicketStatusDisplay($remaining); |
|
178 | - if (empty($this->ticket_status_display)) { |
|
179 | - if ($this->max_attendees === 1) { |
|
180 | - // only ONE attendee is allowed to register at a time |
|
181 | - $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
|
182 | - } elseif ($this->max > 0) { |
|
183 | - $ticket_selector_row_html .= $this->ticketQuantitySelector(); |
|
184 | - } |
|
185 | - } |
|
186 | - $ticket_selector_row_html .= $this->ticket_status_display; |
|
187 | - $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
|
188 | - $ticket_selector_row_html .= $this->ticket_details->display( |
|
189 | - $this->ticket_price, |
|
190 | - $remaining, |
|
191 | - $this->cols |
|
192 | - ); |
|
193 | - $ticket_selector_row_html .= EEH_HTML::tdx(); |
|
194 | - $ticket_selector_row_html .= EEH_HTML::trx(); |
|
195 | - |
|
196 | - |
|
197 | - $this->row++; |
|
198 | - return $ticket_selector_row_html; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * getTicketPriceDetails |
|
204 | - * |
|
205 | - * @return void |
|
206 | - * @throws EE_Error |
|
207 | - */ |
|
208 | - protected function setTicketPriceDetails() |
|
209 | - { |
|
210 | - $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes |
|
211 | - ? $this->ticket->get_ticket_total_with_taxes() |
|
212 | - : $this->ticket->get_ticket_subtotal(); |
|
213 | - $this->ticket_bundle = false; |
|
214 | - $ticket_min = $this->ticket->min(); |
|
215 | - // for ticket bundles, set min and max qty the same |
|
216 | - if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
|
217 | - $this->ticket_price *= $ticket_min; |
|
218 | - $this->ticket_bundle = true; |
|
219 | - } |
|
220 | - $this->ticket_price = apply_filters( |
|
221 | - 'FHEE__ticket_selector_chart_template__ticket_price', |
|
222 | - $this->ticket_price, |
|
223 | - $this->ticket |
|
224 | - ); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * ticketNameTableCell |
|
230 | - * |
|
231 | - * @return string |
|
232 | - * @throws EE_Error |
|
233 | - */ |
|
234 | - protected function ticketNameTableCell() |
|
235 | - { |
|
236 | - $html = EEH_HTML::td( |
|
237 | - '', |
|
238 | - '', |
|
239 | - 'tckt-slctr-tbl-td-name', |
|
240 | - '', |
|
241 | - 'headers="details-' . $this->EVT_ID . '"' |
|
242 | - ); |
|
243 | - $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
|
244 | - $html .= $this->ticket_details->getShowHideLinks(); |
|
245 | - if ($this->ticket->required()) { |
|
246 | - $html .= EEH_HTML::p( |
|
247 | - apply_filters( |
|
248 | - 'FHEE__ticket_selector_chart_template__ticket_required_message', |
|
249 | - esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
|
250 | - ), |
|
251 | - '', |
|
252 | - 'ticket-required-pg' |
|
253 | - ); |
|
254 | - } |
|
255 | - $html .= EEH_HTML::tdx(); |
|
256 | - return $html; |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * ticketPriceTableCell |
|
262 | - * |
|
263 | - * @return string |
|
264 | - * @throws EE_Error |
|
265 | - */ |
|
266 | - protected function ticketPriceTableCell() |
|
267 | - { |
|
268 | - $html = ''; |
|
269 | - if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
270 | - $html .= EEH_HTML::td( |
|
271 | - '', |
|
272 | - '', |
|
273 | - 'tckt-slctr-tbl-td-price jst-rght', |
|
274 | - '', |
|
275 | - 'headers="price-' . $this->EVT_ID . '"' |
|
276 | - ); |
|
277 | - $html .= EEH_HTML::span( |
|
278 | - EEH_Template::format_currency($this->ticket_price), |
|
279 | - '', |
|
280 | - 'tckt-price--nowrap' |
|
281 | - ); |
|
282 | - $html .= $this->ticket->taxable() |
|
283 | - ? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text') |
|
284 | - : ''; |
|
285 | - $html .= ' '; |
|
286 | - // phpcs:disable WordPress.WP.I18n.NoEmptyStrings |
|
287 | - $html .= EEH_HTML::span( |
|
288 | - $this->ticket_bundle |
|
289 | - ? apply_filters( |
|
290 | - 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
|
291 | - __(' / bundle', 'event_espresso') |
|
292 | - ) |
|
293 | - : apply_filters( |
|
294 | - 'FHEE__ticket_selector_chart_template__per_ticket_text', |
|
295 | - __('', 'event_espresso') |
|
296 | - ), |
|
297 | - '', |
|
298 | - 'smaller-text no-bold' |
|
299 | - ); |
|
300 | - $html .= ' '; |
|
301 | - $html .= EEH_HTML::tdx(); |
|
302 | - $this->cols++; |
|
303 | - } |
|
304 | - return $html; |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * onlyOneAttendeeCanRegister |
|
310 | - * |
|
311 | - * @return string |
|
312 | - */ |
|
313 | - protected function onlyOneAttendeeCanRegister() |
|
314 | - { |
|
315 | - // display submit button since we have tickets available |
|
316 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
317 | - $this->hidden_input_qty = false; |
|
318 | - $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
319 | - $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
320 | - $html .= esc_html__('Select this ticket', 'event_espresso') . '</label>'; |
|
321 | - $html .= '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
322 | - $html .= ' id="' . $id . '"'; |
|
323 | - $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
324 | - $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
|
325 | - $html .= ' title=""/>'; |
|
326 | - return $html; |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * ticketQuantitySelector |
|
332 | - * |
|
333 | - * @return string |
|
334 | - * @throws EE_Error |
|
335 | - */ |
|
336 | - protected function ticketQuantitySelector() |
|
337 | - { |
|
338 | - // display submit button since we have tickets available |
|
339 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
340 | - $this->hidden_input_qty = false; |
|
341 | - $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
342 | - $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
343 | - $html .= esc_html__('Quantity', 'event_espresso') . '</label>'; |
|
344 | - $html .= '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
345 | - $html .= ' id="' . $id . '"'; |
|
346 | - $html .= ' class="ticket-selector-tbl-qty-slct">'; |
|
347 | - // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
|
348 | - if ($this->min !== 0 && ! $this->ticket->required()) { |
|
349 | - $html .= '<option value="0"> 0 </option>'; |
|
350 | - } |
|
351 | - // offer ticket quantities from the min to the max |
|
352 | - for ($i = $this->min; $i <= $this->max; $i++) { |
|
353 | - $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
354 | - } |
|
355 | - $html .= '</select>'; |
|
356 | - return $html; |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * getHiddenInputs |
|
362 | - * |
|
363 | - * @return string |
|
364 | - * @throws EE_Error |
|
365 | - */ |
|
366 | - protected function ticketQtyAndIdHiddenInputs() |
|
367 | - { |
|
368 | - $html = ''; |
|
369 | - // depending on group reg we need to change the format for qty |
|
370 | - if ($this->hidden_input_qty) { |
|
371 | - $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
372 | - } |
|
373 | - $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
374 | - $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
375 | - return $html; |
|
376 | - } |
|
21 | + /** |
|
22 | + * @var TicketDetails $ticket_details |
|
23 | + */ |
|
24 | + protected $ticket_details; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var \EE_Ticket_Selector_Config $template_settings |
|
28 | + */ |
|
29 | + protected $template_settings; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var EE_Tax_Config $tax_settings |
|
33 | + */ |
|
34 | + protected $tax_settings; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var boolean $prices_displayed_including_taxes |
|
38 | + */ |
|
39 | + protected $prices_displayed_including_taxes; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var int $row |
|
43 | + */ |
|
44 | + protected $row; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var int $cols |
|
48 | + */ |
|
49 | + protected $cols; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var boolean $hidden_input_qty |
|
53 | + */ |
|
54 | + protected $hidden_input_qty; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var string $ticket_datetime_classes |
|
58 | + */ |
|
59 | + protected $ticket_datetime_classes; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * TicketDetails constructor. |
|
64 | + * |
|
65 | + * @param TicketDetails $ticket_details |
|
66 | + * @param EE_Tax_Config $tax_settings |
|
67 | + * @param int $total_tickets |
|
68 | + * @param int $max_attendees |
|
69 | + * @param int $row |
|
70 | + * @param int $cols |
|
71 | + * @param boolean $required_ticket_sold_out |
|
72 | + * @param string $event_status |
|
73 | + * @param string $ticket_datetime_classes |
|
74 | + * @throws EE_Error |
|
75 | + * @throws UnexpectedEntityException |
|
76 | + */ |
|
77 | + public function __construct( |
|
78 | + TicketDetails $ticket_details, |
|
79 | + EE_Tax_Config $tax_settings, |
|
80 | + $total_tickets, |
|
81 | + $max_attendees, |
|
82 | + $row, |
|
83 | + $cols, |
|
84 | + $required_ticket_sold_out, |
|
85 | + $event_status, |
|
86 | + $ticket_datetime_classes |
|
87 | + ) { |
|
88 | + $this->ticket_details = $ticket_details; |
|
89 | + $this->template_settings = $ticket_details->getTemplateSettings(); |
|
90 | + $this->tax_settings = $tax_settings; |
|
91 | + $this->row = $row; |
|
92 | + $this->cols = $cols; |
|
93 | + $this->ticket_datetime_classes = $ticket_datetime_classes; |
|
94 | + parent::__construct( |
|
95 | + $ticket_details->getTicket(), |
|
96 | + $max_attendees, |
|
97 | + $ticket_details->getDateFormat(), |
|
98 | + $event_status, |
|
99 | + $required_ticket_sold_out, |
|
100 | + $total_tickets |
|
101 | + ); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * other ticket rows will need to know if a required ticket is sold out, |
|
107 | + * so that they are not offered for sale |
|
108 | + * |
|
109 | + * @return boolean |
|
110 | + */ |
|
111 | + public function getRequiredTicketSoldOut() |
|
112 | + { |
|
113 | + return $this->required_ticket_sold_out; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @return int |
|
119 | + */ |
|
120 | + public function getCols() |
|
121 | + { |
|
122 | + return $this->cols; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * getHtml |
|
128 | + * |
|
129 | + * @return string |
|
130 | + * @throws EE_Error |
|
131 | + */ |
|
132 | + public function getHtml() |
|
133 | + { |
|
134 | + $this->min = 0; |
|
135 | + $this->max = $this->ticket->max(); |
|
136 | + $remaining = $this->ticket->remaining(); |
|
137 | + $this->setTicketMinAndMax($remaining); |
|
138 | + // set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
|
139 | + $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
|
140 | + ? $this->ticket->start_date() |
|
141 | + : $this->required_ticket_sold_out; |
|
142 | + $this->setTicketPriceDetails(); |
|
143 | + $this->setTicketStatusClasses($remaining); |
|
144 | + $filtered_row_html = $this->getFilteredRowHtml(); |
|
145 | + if ($filtered_row_html !== false) { |
|
146 | + return $filtered_row_html; |
|
147 | + } |
|
148 | + $ticket_selector_row_html = EEH_HTML::tr( |
|
149 | + '', |
|
150 | + '', |
|
151 | + "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " |
|
152 | + . espresso_get_object_css_class($this->ticket) |
|
153 | + ); |
|
154 | + $filtered_row_content = $this->getFilteredRowContents(); |
|
155 | + if ($filtered_row_content !== false && $this->max_attendees === 1) { |
|
156 | + return $ticket_selector_row_html |
|
157 | + . $filtered_row_content |
|
158 | + . $this->ticketQtyAndIdHiddenInputs() |
|
159 | + . EEH_HTML::trx(); |
|
160 | + } |
|
161 | + if ($filtered_row_content !== false) { |
|
162 | + return $ticket_selector_row_html |
|
163 | + . $filtered_row_content |
|
164 | + . EEH_HTML::trx(); |
|
165 | + } |
|
166 | + $this->hidden_input_qty = $this->max_attendees > 1; |
|
167 | + |
|
168 | + $ticket_selector_row_html .= $this->ticketNameTableCell(); |
|
169 | + $ticket_selector_row_html .= $this->ticketPriceTableCell(); |
|
170 | + $ticket_selector_row_html .= EEH_HTML::td( |
|
171 | + '', |
|
172 | + '', |
|
173 | + 'tckt-slctr-tbl-td-qty cntr', |
|
174 | + '', |
|
175 | + 'headers="quantity-' . $this->EVT_ID . '"' |
|
176 | + ); |
|
177 | + $this->setTicketStatusDisplay($remaining); |
|
178 | + if (empty($this->ticket_status_display)) { |
|
179 | + if ($this->max_attendees === 1) { |
|
180 | + // only ONE attendee is allowed to register at a time |
|
181 | + $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
|
182 | + } elseif ($this->max > 0) { |
|
183 | + $ticket_selector_row_html .= $this->ticketQuantitySelector(); |
|
184 | + } |
|
185 | + } |
|
186 | + $ticket_selector_row_html .= $this->ticket_status_display; |
|
187 | + $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
|
188 | + $ticket_selector_row_html .= $this->ticket_details->display( |
|
189 | + $this->ticket_price, |
|
190 | + $remaining, |
|
191 | + $this->cols |
|
192 | + ); |
|
193 | + $ticket_selector_row_html .= EEH_HTML::tdx(); |
|
194 | + $ticket_selector_row_html .= EEH_HTML::trx(); |
|
195 | + |
|
196 | + |
|
197 | + $this->row++; |
|
198 | + return $ticket_selector_row_html; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * getTicketPriceDetails |
|
204 | + * |
|
205 | + * @return void |
|
206 | + * @throws EE_Error |
|
207 | + */ |
|
208 | + protected function setTicketPriceDetails() |
|
209 | + { |
|
210 | + $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes |
|
211 | + ? $this->ticket->get_ticket_total_with_taxes() |
|
212 | + : $this->ticket->get_ticket_subtotal(); |
|
213 | + $this->ticket_bundle = false; |
|
214 | + $ticket_min = $this->ticket->min(); |
|
215 | + // for ticket bundles, set min and max qty the same |
|
216 | + if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
|
217 | + $this->ticket_price *= $ticket_min; |
|
218 | + $this->ticket_bundle = true; |
|
219 | + } |
|
220 | + $this->ticket_price = apply_filters( |
|
221 | + 'FHEE__ticket_selector_chart_template__ticket_price', |
|
222 | + $this->ticket_price, |
|
223 | + $this->ticket |
|
224 | + ); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * ticketNameTableCell |
|
230 | + * |
|
231 | + * @return string |
|
232 | + * @throws EE_Error |
|
233 | + */ |
|
234 | + protected function ticketNameTableCell() |
|
235 | + { |
|
236 | + $html = EEH_HTML::td( |
|
237 | + '', |
|
238 | + '', |
|
239 | + 'tckt-slctr-tbl-td-name', |
|
240 | + '', |
|
241 | + 'headers="details-' . $this->EVT_ID . '"' |
|
242 | + ); |
|
243 | + $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
|
244 | + $html .= $this->ticket_details->getShowHideLinks(); |
|
245 | + if ($this->ticket->required()) { |
|
246 | + $html .= EEH_HTML::p( |
|
247 | + apply_filters( |
|
248 | + 'FHEE__ticket_selector_chart_template__ticket_required_message', |
|
249 | + esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
|
250 | + ), |
|
251 | + '', |
|
252 | + 'ticket-required-pg' |
|
253 | + ); |
|
254 | + } |
|
255 | + $html .= EEH_HTML::tdx(); |
|
256 | + return $html; |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * ticketPriceTableCell |
|
262 | + * |
|
263 | + * @return string |
|
264 | + * @throws EE_Error |
|
265 | + */ |
|
266 | + protected function ticketPriceTableCell() |
|
267 | + { |
|
268 | + $html = ''; |
|
269 | + if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
270 | + $html .= EEH_HTML::td( |
|
271 | + '', |
|
272 | + '', |
|
273 | + 'tckt-slctr-tbl-td-price jst-rght', |
|
274 | + '', |
|
275 | + 'headers="price-' . $this->EVT_ID . '"' |
|
276 | + ); |
|
277 | + $html .= EEH_HTML::span( |
|
278 | + EEH_Template::format_currency($this->ticket_price), |
|
279 | + '', |
|
280 | + 'tckt-price--nowrap' |
|
281 | + ); |
|
282 | + $html .= $this->ticket->taxable() |
|
283 | + ? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text') |
|
284 | + : ''; |
|
285 | + $html .= ' '; |
|
286 | + // phpcs:disable WordPress.WP.I18n.NoEmptyStrings |
|
287 | + $html .= EEH_HTML::span( |
|
288 | + $this->ticket_bundle |
|
289 | + ? apply_filters( |
|
290 | + 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
|
291 | + __(' / bundle', 'event_espresso') |
|
292 | + ) |
|
293 | + : apply_filters( |
|
294 | + 'FHEE__ticket_selector_chart_template__per_ticket_text', |
|
295 | + __('', 'event_espresso') |
|
296 | + ), |
|
297 | + '', |
|
298 | + 'smaller-text no-bold' |
|
299 | + ); |
|
300 | + $html .= ' '; |
|
301 | + $html .= EEH_HTML::tdx(); |
|
302 | + $this->cols++; |
|
303 | + } |
|
304 | + return $html; |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * onlyOneAttendeeCanRegister |
|
310 | + * |
|
311 | + * @return string |
|
312 | + */ |
|
313 | + protected function onlyOneAttendeeCanRegister() |
|
314 | + { |
|
315 | + // display submit button since we have tickets available |
|
316 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
317 | + $this->hidden_input_qty = false; |
|
318 | + $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
319 | + $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
320 | + $html .= esc_html__('Select this ticket', 'event_espresso') . '</label>'; |
|
321 | + $html .= '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
322 | + $html .= ' id="' . $id . '"'; |
|
323 | + $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
324 | + $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
|
325 | + $html .= ' title=""/>'; |
|
326 | + return $html; |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * ticketQuantitySelector |
|
332 | + * |
|
333 | + * @return string |
|
334 | + * @throws EE_Error |
|
335 | + */ |
|
336 | + protected function ticketQuantitySelector() |
|
337 | + { |
|
338 | + // display submit button since we have tickets available |
|
339 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
340 | + $this->hidden_input_qty = false; |
|
341 | + $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
342 | + $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
343 | + $html .= esc_html__('Quantity', 'event_espresso') . '</label>'; |
|
344 | + $html .= '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
345 | + $html .= ' id="' . $id . '"'; |
|
346 | + $html .= ' class="ticket-selector-tbl-qty-slct">'; |
|
347 | + // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
|
348 | + if ($this->min !== 0 && ! $this->ticket->required()) { |
|
349 | + $html .= '<option value="0"> 0 </option>'; |
|
350 | + } |
|
351 | + // offer ticket quantities from the min to the max |
|
352 | + for ($i = $this->min; $i <= $this->max; $i++) { |
|
353 | + $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
354 | + } |
|
355 | + $html .= '</select>'; |
|
356 | + return $html; |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * getHiddenInputs |
|
362 | + * |
|
363 | + * @return string |
|
364 | + * @throws EE_Error |
|
365 | + */ |
|
366 | + protected function ticketQtyAndIdHiddenInputs() |
|
367 | + { |
|
368 | + $html = ''; |
|
369 | + // depending on group reg we need to change the format for qty |
|
370 | + if ($this->hidden_input_qty) { |
|
371 | + $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
372 | + } |
|
373 | + $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
374 | + $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
375 | + return $html; |
|
376 | + } |
|
377 | 377 | } |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | '', |
173 | 173 | 'tckt-slctr-tbl-td-qty cntr', |
174 | 174 | '', |
175 | - 'headers="quantity-' . $this->EVT_ID . '"' |
|
175 | + 'headers="quantity-'.$this->EVT_ID.'"' |
|
176 | 176 | ); |
177 | 177 | $this->setTicketStatusDisplay($remaining); |
178 | 178 | if (empty($this->ticket_status_display)) { |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | '', |
239 | 239 | 'tckt-slctr-tbl-td-name', |
240 | 240 | '', |
241 | - 'headers="details-' . $this->EVT_ID . '"' |
|
241 | + 'headers="details-'.$this->EVT_ID.'"' |
|
242 | 242 | ); |
243 | 243 | $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
244 | 244 | $html .= $this->ticket_details->getShowHideLinks(); |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | '', |
273 | 273 | 'tckt-slctr-tbl-td-price jst-rght', |
274 | 274 | '', |
275 | - 'headers="price-' . $this->EVT_ID . '"' |
|
275 | + 'headers="price-'.$this->EVT_ID.'"' |
|
276 | 276 | ); |
277 | 277 | $html .= EEH_HTML::span( |
278 | 278 | EEH_Template::format_currency($this->ticket_price), |
@@ -315,12 +315,12 @@ discard block |
||
315 | 315 | // display submit button since we have tickets available |
316 | 316 | add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
317 | 317 | $this->hidden_input_qty = false; |
318 | - $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
319 | - $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
320 | - $html .= esc_html__('Select this ticket', 'event_espresso') . '</label>'; |
|
321 | - $html .= '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
322 | - $html .= ' id="' . $id . '"'; |
|
323 | - $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
318 | + $id = 'ticket-selector-tbl-qty-slct-'.$this->EVT_ID.'-'.$this->row; |
|
319 | + $html = '<label class="ee-a11y-screen-reader-text" for="'.$id.'">'; |
|
320 | + $html .= esc_html__('Select this ticket', 'event_espresso').'</label>'; |
|
321 | + $html .= '<input type="radio" name="tkt-slctr-qty-'.$this->EVT_ID.'"'; |
|
322 | + $html .= ' id="'.$id.'"'; |
|
323 | + $html .= ' class="ticket-selector-tbl-qty-slct" value="'.$this->row.'-1"'; |
|
324 | 324 | $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
325 | 325 | $html .= ' title=""/>'; |
326 | 326 | return $html; |
@@ -338,11 +338,11 @@ discard block |
||
338 | 338 | // display submit button since we have tickets available |
339 | 339 | add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
340 | 340 | $this->hidden_input_qty = false; |
341 | - $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
342 | - $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
343 | - $html .= esc_html__('Quantity', 'event_espresso') . '</label>'; |
|
344 | - $html .= '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
345 | - $html .= ' id="' . $id . '"'; |
|
341 | + $id = 'ticket-selector-tbl-qty-slct-'.$this->EVT_ID.'-'.$this->row; |
|
342 | + $html = '<label class="ee-a11y-screen-reader-text" for="'.$id.'">'; |
|
343 | + $html .= esc_html__('Quantity', 'event_espresso').'</label>'; |
|
344 | + $html .= '<select name="tkt-slctr-qty-'.$this->EVT_ID.'[]"'; |
|
345 | + $html .= ' id="'.$id.'"'; |
|
346 | 346 | $html .= ' class="ticket-selector-tbl-qty-slct">'; |
347 | 347 | // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
348 | 348 | if ($this->min !== 0 && ! $this->ticket->required()) { |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | } |
351 | 351 | // offer ticket quantities from the min to the max |
352 | 352 | for ($i = $this->min; $i <= $this->max; $i++) { |
353 | - $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
353 | + $html .= '<option value="'.$i.'"> '.$i.' </option>'; |
|
354 | 354 | } |
355 | 355 | $html .= '</select>'; |
356 | 356 | return $html; |
@@ -368,10 +368,10 @@ discard block |
||
368 | 368 | $html = ''; |
369 | 369 | // depending on group reg we need to change the format for qty |
370 | 370 | if ($this->hidden_input_qty) { |
371 | - $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
371 | + $html .= '<input type="hidden" name="tkt-slctr-qty-'.$this->EVT_ID.'[]" value="0"/>'; |
|
372 | 372 | } |
373 | - $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
374 | - $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
373 | + $html .= '<input type="hidden" name="tkt-slctr-ticket-id-'.$this->EVT_ID.'[]"'; |
|
374 | + $html .= ' value="'.$this->ticket->ID().'"/>'; |
|
375 | 375 | return $html; |
376 | 376 | } |
377 | 377 | } |
@@ -22,201 +22,201 @@ |
||
22 | 22 | { |
23 | 23 | |
24 | 24 | |
25 | - protected function _init_props() |
|
26 | - { |
|
27 | - $this->label = __('Line Item List Shortcodes', 'event_espresso'); |
|
28 | - $this->description = __('All shortcodes specific to line item lists', 'event_espresso'); |
|
29 | - $this->_shortcodes = array( |
|
30 | - '[TICKET_LINE_ITEM_LIST]' => __('Outputs a list of ticket line items.', 'event_espresso'), |
|
31 | - '[TAX_LINE_ITEM_LIST]' => __('Outputs a list of tax line items.', 'event_espresso'), |
|
32 | - '[ADDITIONAL_LINE_ITEM_LIST]' => __( |
|
33 | - 'Outputs a list of additional line items (other charges or discounts)', |
|
34 | - 'event_espresso' |
|
35 | - ), |
|
36 | - '[PRICE_MODIFIER_LINE_ITEM_LIST]' => __('Outputs a list of price modifier line items', 'event_espresso'), |
|
37 | - ); |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - protected function _parser($shortcode) |
|
42 | - { |
|
43 | - |
|
44 | - switch ($shortcode) { |
|
45 | - case '[TICKET_LINE_ITEM_LIST]': |
|
46 | - return $this->_get_ticket_line_item_list(); |
|
47 | - |
|
48 | - case '[TAX_LINE_ITEM_LIST]': |
|
49 | - return $this->_get_tax_line_item_list(); |
|
50 | - |
|
51 | - case '[PRICE_MODIFIER_LINE_ITEM_LIST]': |
|
52 | - return $this->_get_price_mod_line_item_list(); |
|
53 | - |
|
54 | - case '[ADDITIONAL_LINE_ITEM_LIST]': |
|
55 | - return $this->_get_additional_line_item_list(); |
|
56 | - |
|
57 | - default: |
|
58 | - return ''; |
|
59 | - } |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event. |
|
65 | - * |
|
66 | - * @since 4.5.0 |
|
67 | - * |
|
68 | - * @return string parsed ticket line item list. |
|
69 | - */ |
|
70 | - private function _get_ticket_line_item_list() |
|
71 | - { |
|
72 | - $this->_validate_list_requirements(); |
|
73 | - |
|
74 | - if (! $this->_data['data'] instanceof EE_Ticket) { |
|
75 | - return ''; |
|
76 | - } |
|
77 | - |
|
78 | - $valid_shortcodes = array('line_item', 'line_item_list', 'ticket'); |
|
79 | - |
|
80 | - $ticket = $this->_data['data']; |
|
81 | - $templates = $this->_extra_data['template']; |
|
82 | - $addressee_obj = $this->_extra_data['data']; |
|
83 | - |
|
84 | - // made it here so we have an EE_Ticket, so we should have what we need. |
|
85 | - $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
86 | - ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
87 | - $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
88 | - ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
89 | - |
|
90 | - $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
|
91 | - : $templates['ticket_line_item_pms']; |
|
92 | - |
|
93 | - if (empty($ticket_line_item) || empty($sub_line_items)) { |
|
94 | - return ''; |
|
95 | - } |
|
96 | - |
|
97 | - // now we just return the appropriate template parsed for each ticket. |
|
98 | - return $this->_shortcode_helper->parse_line_item_list_template( |
|
99 | - $template, |
|
100 | - $ticket_line_item, |
|
101 | - $valid_shortcodes, |
|
102 | - $this->_extra_data |
|
103 | - ); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction. |
|
109 | - * |
|
110 | - * @return string parsed tax line item list. |
|
111 | - * @throws EE_Error |
|
112 | - * @since 4.5.0 |
|
113 | - */ |
|
114 | - private function _get_tax_line_item_list() |
|
115 | - { |
|
116 | - /** @var EE_Admin_Config $admin_config */ |
|
117 | - $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
118 | - if ($admin_config->useAdvancedEditor()) { |
|
119 | - return ''; |
|
120 | - } |
|
121 | - $this->_validate_list_requirements(); |
|
122 | - |
|
123 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
124 | - return ''; |
|
125 | - } |
|
126 | - |
|
127 | - // made it here so we're good to go. |
|
128 | - $valid_shortcodes = array('line_item'); |
|
129 | - $templates = $this->_data['template']; |
|
130 | - |
|
131 | - $tax_line_items = $this->_data['data']->tax_line_items; |
|
132 | - $line_item_list = ''; |
|
133 | - foreach ($tax_line_items as $line_item) { |
|
134 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
135 | - $templates['tax_line_item_list'], |
|
136 | - $line_item, |
|
137 | - $valid_shortcodes, |
|
138 | - $this->_extra_data |
|
139 | - ); |
|
140 | - } |
|
141 | - |
|
142 | - return $line_item_list; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction. |
|
147 | - * |
|
148 | - * @since 4.5.0 |
|
149 | - * |
|
150 | - * @return string parsed other line item list. |
|
151 | - */ |
|
152 | - private function _get_additional_line_item_list() |
|
153 | - { |
|
154 | - |
|
155 | - $this->_validate_list_requirements(); |
|
156 | - |
|
157 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
158 | - return ''; |
|
159 | - } |
|
160 | - |
|
161 | - // made it here so we're good to go. |
|
162 | - $valid_shortcodes = array('line_item'); |
|
163 | - $templates = $this->_data['template']; |
|
164 | - |
|
165 | - $additional_line_items = $this->_data['data']->additional_line_items; |
|
166 | - $line_item_list = ''; |
|
167 | - foreach ($additional_line_items as $line_item) { |
|
168 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
169 | - $templates['additional_line_item_list'], |
|
170 | - $line_item, |
|
171 | - $valid_shortcodes, |
|
172 | - $this->_extra_data |
|
173 | - ); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - return $line_item_list; |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a |
|
183 | - * parent ticket line item. |
|
184 | - * |
|
185 | - * @since 4.5.0 |
|
186 | - * |
|
187 | - * @return string parsed price modifier line item list. |
|
188 | - */ |
|
189 | - private function _get_price_mod_line_item_list() |
|
190 | - { |
|
191 | - $this->_validate_list_requirements(); |
|
192 | - |
|
193 | - if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
194 | - return ''; |
|
195 | - } |
|
196 | - |
|
197 | - // made it here so we're good to go. |
|
198 | - $main_line_item = $this->_data['data']; |
|
199 | - $templates = $this->_extra_data['template']; |
|
200 | - $addressee_obj = $this->_extra_data['data']; |
|
201 | - |
|
202 | - $valid_shortcodes = array('line_item'); |
|
203 | - |
|
204 | - $main_line_item_id = $main_line_item->ID(); |
|
205 | - |
|
206 | - $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
207 | - ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
208 | - |
|
209 | - $line_item_list = ''; |
|
210 | - |
|
211 | - foreach ($price_mod_line_items as $line_item) { |
|
212 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
213 | - $templates['price_modifier_line_item_list'], |
|
214 | - $line_item, |
|
215 | - $valid_shortcodes, |
|
216 | - $this->_extra_data |
|
217 | - ); |
|
218 | - } |
|
219 | - |
|
220 | - return $line_item_list; |
|
221 | - } |
|
25 | + protected function _init_props() |
|
26 | + { |
|
27 | + $this->label = __('Line Item List Shortcodes', 'event_espresso'); |
|
28 | + $this->description = __('All shortcodes specific to line item lists', 'event_espresso'); |
|
29 | + $this->_shortcodes = array( |
|
30 | + '[TICKET_LINE_ITEM_LIST]' => __('Outputs a list of ticket line items.', 'event_espresso'), |
|
31 | + '[TAX_LINE_ITEM_LIST]' => __('Outputs a list of tax line items.', 'event_espresso'), |
|
32 | + '[ADDITIONAL_LINE_ITEM_LIST]' => __( |
|
33 | + 'Outputs a list of additional line items (other charges or discounts)', |
|
34 | + 'event_espresso' |
|
35 | + ), |
|
36 | + '[PRICE_MODIFIER_LINE_ITEM_LIST]' => __('Outputs a list of price modifier line items', 'event_espresso'), |
|
37 | + ); |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + protected function _parser($shortcode) |
|
42 | + { |
|
43 | + |
|
44 | + switch ($shortcode) { |
|
45 | + case '[TICKET_LINE_ITEM_LIST]': |
|
46 | + return $this->_get_ticket_line_item_list(); |
|
47 | + |
|
48 | + case '[TAX_LINE_ITEM_LIST]': |
|
49 | + return $this->_get_tax_line_item_list(); |
|
50 | + |
|
51 | + case '[PRICE_MODIFIER_LINE_ITEM_LIST]': |
|
52 | + return $this->_get_price_mod_line_item_list(); |
|
53 | + |
|
54 | + case '[ADDITIONAL_LINE_ITEM_LIST]': |
|
55 | + return $this->_get_additional_line_item_list(); |
|
56 | + |
|
57 | + default: |
|
58 | + return ''; |
|
59 | + } |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event. |
|
65 | + * |
|
66 | + * @since 4.5.0 |
|
67 | + * |
|
68 | + * @return string parsed ticket line item list. |
|
69 | + */ |
|
70 | + private function _get_ticket_line_item_list() |
|
71 | + { |
|
72 | + $this->_validate_list_requirements(); |
|
73 | + |
|
74 | + if (! $this->_data['data'] instanceof EE_Ticket) { |
|
75 | + return ''; |
|
76 | + } |
|
77 | + |
|
78 | + $valid_shortcodes = array('line_item', 'line_item_list', 'ticket'); |
|
79 | + |
|
80 | + $ticket = $this->_data['data']; |
|
81 | + $templates = $this->_extra_data['template']; |
|
82 | + $addressee_obj = $this->_extra_data['data']; |
|
83 | + |
|
84 | + // made it here so we have an EE_Ticket, so we should have what we need. |
|
85 | + $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
86 | + ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
87 | + $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
88 | + ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
89 | + |
|
90 | + $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
|
91 | + : $templates['ticket_line_item_pms']; |
|
92 | + |
|
93 | + if (empty($ticket_line_item) || empty($sub_line_items)) { |
|
94 | + return ''; |
|
95 | + } |
|
96 | + |
|
97 | + // now we just return the appropriate template parsed for each ticket. |
|
98 | + return $this->_shortcode_helper->parse_line_item_list_template( |
|
99 | + $template, |
|
100 | + $ticket_line_item, |
|
101 | + $valid_shortcodes, |
|
102 | + $this->_extra_data |
|
103 | + ); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction. |
|
109 | + * |
|
110 | + * @return string parsed tax line item list. |
|
111 | + * @throws EE_Error |
|
112 | + * @since 4.5.0 |
|
113 | + */ |
|
114 | + private function _get_tax_line_item_list() |
|
115 | + { |
|
116 | + /** @var EE_Admin_Config $admin_config */ |
|
117 | + $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
118 | + if ($admin_config->useAdvancedEditor()) { |
|
119 | + return ''; |
|
120 | + } |
|
121 | + $this->_validate_list_requirements(); |
|
122 | + |
|
123 | + if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
124 | + return ''; |
|
125 | + } |
|
126 | + |
|
127 | + // made it here so we're good to go. |
|
128 | + $valid_shortcodes = array('line_item'); |
|
129 | + $templates = $this->_data['template']; |
|
130 | + |
|
131 | + $tax_line_items = $this->_data['data']->tax_line_items; |
|
132 | + $line_item_list = ''; |
|
133 | + foreach ($tax_line_items as $line_item) { |
|
134 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
135 | + $templates['tax_line_item_list'], |
|
136 | + $line_item, |
|
137 | + $valid_shortcodes, |
|
138 | + $this->_extra_data |
|
139 | + ); |
|
140 | + } |
|
141 | + |
|
142 | + return $line_item_list; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction. |
|
147 | + * |
|
148 | + * @since 4.5.0 |
|
149 | + * |
|
150 | + * @return string parsed other line item list. |
|
151 | + */ |
|
152 | + private function _get_additional_line_item_list() |
|
153 | + { |
|
154 | + |
|
155 | + $this->_validate_list_requirements(); |
|
156 | + |
|
157 | + if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
158 | + return ''; |
|
159 | + } |
|
160 | + |
|
161 | + // made it here so we're good to go. |
|
162 | + $valid_shortcodes = array('line_item'); |
|
163 | + $templates = $this->_data['template']; |
|
164 | + |
|
165 | + $additional_line_items = $this->_data['data']->additional_line_items; |
|
166 | + $line_item_list = ''; |
|
167 | + foreach ($additional_line_items as $line_item) { |
|
168 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
169 | + $templates['additional_line_item_list'], |
|
170 | + $line_item, |
|
171 | + $valid_shortcodes, |
|
172 | + $this->_extra_data |
|
173 | + ); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + return $line_item_list; |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a |
|
183 | + * parent ticket line item. |
|
184 | + * |
|
185 | + * @since 4.5.0 |
|
186 | + * |
|
187 | + * @return string parsed price modifier line item list. |
|
188 | + */ |
|
189 | + private function _get_price_mod_line_item_list() |
|
190 | + { |
|
191 | + $this->_validate_list_requirements(); |
|
192 | + |
|
193 | + if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
194 | + return ''; |
|
195 | + } |
|
196 | + |
|
197 | + // made it here so we're good to go. |
|
198 | + $main_line_item = $this->_data['data']; |
|
199 | + $templates = $this->_extra_data['template']; |
|
200 | + $addressee_obj = $this->_extra_data['data']; |
|
201 | + |
|
202 | + $valid_shortcodes = array('line_item'); |
|
203 | + |
|
204 | + $main_line_item_id = $main_line_item->ID(); |
|
205 | + |
|
206 | + $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
207 | + ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
208 | + |
|
209 | + $line_item_list = ''; |
|
210 | + |
|
211 | + foreach ($price_mod_line_items as $line_item) { |
|
212 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
213 | + $templates['price_modifier_line_item_list'], |
|
214 | + $line_item, |
|
215 | + $valid_shortcodes, |
|
216 | + $this->_extra_data |
|
217 | + ); |
|
218 | + } |
|
219 | + |
|
220 | + return $line_item_list; |
|
221 | + } |
|
222 | 222 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | { |
72 | 72 | $this->_validate_list_requirements(); |
73 | 73 | |
74 | - if (! $this->_data['data'] instanceof EE_Ticket) { |
|
74 | + if ( ! $this->_data['data'] instanceof EE_Ticket) { |
|
75 | 75 | return ''; |
76 | 76 | } |
77 | 77 | |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | $addressee_obj = $this->_extra_data['data']; |
83 | 83 | |
84 | 84 | // made it here so we have an EE_Ticket, so we should have what we need. |
85 | - $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
86 | - ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
87 | - $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
88 | - ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
85 | + $ticket_line_item = isset($addressee_obj->tickets[$ticket->ID()]['line_item']) |
|
86 | + ? $addressee_obj->tickets[$ticket->ID()]['line_item'] : null; |
|
87 | + $sub_line_items = isset($addressee_obj->tickets[$ticket->ID()]['sub_line_items']) |
|
88 | + ? $addressee_obj->tickets[$ticket->ID()]['sub_line_items'] : array(); |
|
89 | 89 | |
90 | 90 | $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
91 | 91 | : $templates['ticket_line_item_pms']; |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | } |
121 | 121 | $this->_validate_list_requirements(); |
122 | 122 | |
123 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
123 | + if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
124 | 124 | return ''; |
125 | 125 | } |
126 | 126 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | |
155 | 155 | $this->_validate_list_requirements(); |
156 | 156 | |
157 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
157 | + if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
158 | 158 | return ''; |
159 | 159 | } |
160 | 160 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | { |
191 | 191 | $this->_validate_list_requirements(); |
192 | 192 | |
193 | - if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
193 | + if ( ! $this->_data['data'] instanceof EE_Line_Item) { |
|
194 | 194 | return ''; |
195 | 195 | } |
196 | 196 | |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | |
204 | 204 | $main_line_item_id = $main_line_item->ID(); |
205 | 205 | |
206 | - $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
207 | - ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
206 | + $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[$main_line_item_id]['children']) |
|
207 | + ? $addressee_obj->line_items_with_children[$main_line_item_id]['children'] : array(); |
|
208 | 208 | |
209 | 209 | $line_item_list = ''; |
210 | 210 |
@@ -17,192 +17,192 @@ |
||
17 | 17 | class RegistrantForm extends EE_Form_Section_Proper |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var EEM_Event_Question_Group |
|
22 | - */ |
|
23 | - public $event_question_group_model; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - private $has_questions = false; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * RegistrantForm constructor. |
|
33 | - * |
|
34 | - * @param EE_Registration $registration |
|
35 | - * @param bool $admin_request |
|
36 | - * @param bool $copy_attendee_info |
|
37 | - * @param callable $enablePrintCopyInfo |
|
38 | - * @param EEM_Event_Question_Group $event_question_group_model |
|
39 | - * @throws EE_Error |
|
40 | - * @throws ReflectionException |
|
41 | - */ |
|
42 | - public function __construct( |
|
43 | - EE_Registration $registration, |
|
44 | - bool $admin_request, |
|
45 | - bool $copy_attendee_info, |
|
46 | - callable $enablePrintCopyInfo, |
|
47 | - EEM_Event_Question_Group $event_question_group_model |
|
48 | - ) { |
|
49 | - $this->event_question_group_model = $event_question_group_model; |
|
50 | - parent::__construct( |
|
51 | - $this->generateFormArgs($registration, $admin_request, $copy_attendee_info, $enablePrintCopyInfo) |
|
52 | - ); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - public function hasQuestions(): bool |
|
60 | - { |
|
61 | - return $this->has_questions; |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param EE_Registration $registration |
|
67 | - * @param bool $admin_request |
|
68 | - * @param bool $copy_attendee_info |
|
69 | - * @param callable $enablePrintCopyInfo |
|
70 | - * @return array |
|
71 | - * @throws EE_Error |
|
72 | - * @throws ReflectionException |
|
73 | - */ |
|
74 | - private function generateFormArgs( |
|
75 | - EE_Registration $registration, |
|
76 | - bool $admin_request, |
|
77 | - bool $copy_attendee_info, |
|
78 | - callable $enablePrintCopyInfo |
|
79 | - ): array { |
|
80 | - static $attendee_nmbr = 1; |
|
81 | - $form_args = []; |
|
82 | - // verify that registration has valid event |
|
83 | - if ($registration->event() instanceof EE_Event) { |
|
84 | - $field_name = 'Event_Question_Group.' . $this->event_question_group_model->fieldNameForContext( |
|
85 | - $registration->is_primary_registrant() |
|
86 | - ); |
|
87 | - $question_groups = $registration->event()->question_groups( |
|
88 | - apply_filters( |
|
89 | - // @codingStandardsIgnoreStart |
|
90 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
91 | - // @codingStandardsIgnoreEnd |
|
92 | - [ |
|
93 | - [ |
|
94 | - 'Event.EVT_ID' => $registration->event()->ID(), |
|
95 | - $field_name => true, |
|
96 | - ], |
|
97 | - 'order_by' => ['QSG_order' => 'ASC'], |
|
98 | - ], |
|
99 | - $registration, |
|
100 | - $this |
|
101 | - ) |
|
102 | - ); |
|
103 | - if ($question_groups) { |
|
104 | - // array of params to pass to parent constructor |
|
105 | - $form_args = [ |
|
106 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
107 | - 'html_class' => 'ee-reg-form-attendee-dv', |
|
108 | - 'html_style' => $admin_request |
|
109 | - ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
110 | - : '', |
|
111 | - 'subsections' => [], |
|
112 | - 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
113 | - [ |
|
114 | - 'legend_class' => 'spco-attendee-lgnd', |
|
115 | - 'legend_text' => sprintf( |
|
116 | - esc_html_x( |
|
117 | - 'Attendee %d', |
|
118 | - 'Attendee 123', |
|
119 | - 'event_espresso' |
|
120 | - ), |
|
121 | - $attendee_nmbr |
|
122 | - ), |
|
123 | - ] |
|
124 | - ), |
|
125 | - ]; |
|
126 | - foreach ($question_groups as $question_group) { |
|
127 | - if ($question_group instanceof EE_Question_Group) { |
|
128 | - $question_group_reg_form = LoaderFactory::getNew( |
|
129 | - RegFormQuestionGroup::class, |
|
130 | - [$registration, $question_group, $admin_request] |
|
131 | - ); |
|
132 | - $form_args['subsections'][ $question_group->identifier() ] = apply_filters( |
|
133 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
134 | - $question_group_reg_form, |
|
135 | - $registration, |
|
136 | - $question_group, |
|
137 | - $this |
|
138 | - ); |
|
139 | - } |
|
140 | - } |
|
141 | - // add hidden input |
|
142 | - $form_args['subsections']['additional_attendee_reg_info'] = $this->additionalAttendeeRegInfoInput( |
|
143 | - $registration |
|
144 | - ); |
|
145 | - |
|
146 | - // If we have question groups for additional attendees, then display the copy options |
|
147 | - $printCopyInfo = apply_filters( |
|
148 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo', |
|
149 | - $attendee_nmbr > 1 && $copy_attendee_info, |
|
150 | - $attendee_nmbr |
|
151 | - ); |
|
152 | - if ($printCopyInfo) { |
|
153 | - $enablePrintCopyInfo(); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - if ($registration->is_primary_registrant()) { |
|
158 | - // generate hidden input |
|
159 | - $form_args['subsections']['primary_registrant'] = $this->additionalPrimaryRegistrantInputs( |
|
160 | - $registration |
|
161 | - ); |
|
162 | - } |
|
163 | - } |
|
164 | - } |
|
165 | - $attendee_nmbr++; |
|
166 | - |
|
167 | - // Increment the reg forms number if form is valid. |
|
168 | - if (! empty($form_args)) { |
|
169 | - $this->has_questions = true; |
|
170 | - } |
|
171 | - |
|
172 | - return $form_args; |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * @param EE_Registration $registration |
|
178 | - * @return EE_Form_Input_Base |
|
179 | - * @throws EE_Error |
|
180 | - */ |
|
181 | - private function additionalAttendeeRegInfoInput(EE_Registration $registration) |
|
182 | - { |
|
183 | - // generate hidden input |
|
184 | - return new EE_Hidden_Input( |
|
185 | - [ |
|
186 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
187 | - 'default' => true, |
|
188 | - ] |
|
189 | - ); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @param EE_Registration $registration |
|
195 | - * @return EE_Form_Input_Base |
|
196 | - * @throws EE_Error |
|
197 | - */ |
|
198 | - private function additionalPrimaryRegistrantInputs(EE_Registration $registration) |
|
199 | - { |
|
200 | - // generate hidden input |
|
201 | - return new EE_Hidden_Input( |
|
202 | - [ |
|
203 | - 'html_id' => 'primary_registrant', |
|
204 | - 'default' => $registration->reg_url_link(), |
|
205 | - ] |
|
206 | - ); |
|
207 | - } |
|
20 | + /** |
|
21 | + * @var EEM_Event_Question_Group |
|
22 | + */ |
|
23 | + public $event_question_group_model; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + private $has_questions = false; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * RegistrantForm constructor. |
|
33 | + * |
|
34 | + * @param EE_Registration $registration |
|
35 | + * @param bool $admin_request |
|
36 | + * @param bool $copy_attendee_info |
|
37 | + * @param callable $enablePrintCopyInfo |
|
38 | + * @param EEM_Event_Question_Group $event_question_group_model |
|
39 | + * @throws EE_Error |
|
40 | + * @throws ReflectionException |
|
41 | + */ |
|
42 | + public function __construct( |
|
43 | + EE_Registration $registration, |
|
44 | + bool $admin_request, |
|
45 | + bool $copy_attendee_info, |
|
46 | + callable $enablePrintCopyInfo, |
|
47 | + EEM_Event_Question_Group $event_question_group_model |
|
48 | + ) { |
|
49 | + $this->event_question_group_model = $event_question_group_model; |
|
50 | + parent::__construct( |
|
51 | + $this->generateFormArgs($registration, $admin_request, $copy_attendee_info, $enablePrintCopyInfo) |
|
52 | + ); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + public function hasQuestions(): bool |
|
60 | + { |
|
61 | + return $this->has_questions; |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param EE_Registration $registration |
|
67 | + * @param bool $admin_request |
|
68 | + * @param bool $copy_attendee_info |
|
69 | + * @param callable $enablePrintCopyInfo |
|
70 | + * @return array |
|
71 | + * @throws EE_Error |
|
72 | + * @throws ReflectionException |
|
73 | + */ |
|
74 | + private function generateFormArgs( |
|
75 | + EE_Registration $registration, |
|
76 | + bool $admin_request, |
|
77 | + bool $copy_attendee_info, |
|
78 | + callable $enablePrintCopyInfo |
|
79 | + ): array { |
|
80 | + static $attendee_nmbr = 1; |
|
81 | + $form_args = []; |
|
82 | + // verify that registration has valid event |
|
83 | + if ($registration->event() instanceof EE_Event) { |
|
84 | + $field_name = 'Event_Question_Group.' . $this->event_question_group_model->fieldNameForContext( |
|
85 | + $registration->is_primary_registrant() |
|
86 | + ); |
|
87 | + $question_groups = $registration->event()->question_groups( |
|
88 | + apply_filters( |
|
89 | + // @codingStandardsIgnoreStart |
|
90 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
91 | + // @codingStandardsIgnoreEnd |
|
92 | + [ |
|
93 | + [ |
|
94 | + 'Event.EVT_ID' => $registration->event()->ID(), |
|
95 | + $field_name => true, |
|
96 | + ], |
|
97 | + 'order_by' => ['QSG_order' => 'ASC'], |
|
98 | + ], |
|
99 | + $registration, |
|
100 | + $this |
|
101 | + ) |
|
102 | + ); |
|
103 | + if ($question_groups) { |
|
104 | + // array of params to pass to parent constructor |
|
105 | + $form_args = [ |
|
106 | + 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
107 | + 'html_class' => 'ee-reg-form-attendee-dv', |
|
108 | + 'html_style' => $admin_request |
|
109 | + ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
110 | + : '', |
|
111 | + 'subsections' => [], |
|
112 | + 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
113 | + [ |
|
114 | + 'legend_class' => 'spco-attendee-lgnd', |
|
115 | + 'legend_text' => sprintf( |
|
116 | + esc_html_x( |
|
117 | + 'Attendee %d', |
|
118 | + 'Attendee 123', |
|
119 | + 'event_espresso' |
|
120 | + ), |
|
121 | + $attendee_nmbr |
|
122 | + ), |
|
123 | + ] |
|
124 | + ), |
|
125 | + ]; |
|
126 | + foreach ($question_groups as $question_group) { |
|
127 | + if ($question_group instanceof EE_Question_Group) { |
|
128 | + $question_group_reg_form = LoaderFactory::getNew( |
|
129 | + RegFormQuestionGroup::class, |
|
130 | + [$registration, $question_group, $admin_request] |
|
131 | + ); |
|
132 | + $form_args['subsections'][ $question_group->identifier() ] = apply_filters( |
|
133 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
134 | + $question_group_reg_form, |
|
135 | + $registration, |
|
136 | + $question_group, |
|
137 | + $this |
|
138 | + ); |
|
139 | + } |
|
140 | + } |
|
141 | + // add hidden input |
|
142 | + $form_args['subsections']['additional_attendee_reg_info'] = $this->additionalAttendeeRegInfoInput( |
|
143 | + $registration |
|
144 | + ); |
|
145 | + |
|
146 | + // If we have question groups for additional attendees, then display the copy options |
|
147 | + $printCopyInfo = apply_filters( |
|
148 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo', |
|
149 | + $attendee_nmbr > 1 && $copy_attendee_info, |
|
150 | + $attendee_nmbr |
|
151 | + ); |
|
152 | + if ($printCopyInfo) { |
|
153 | + $enablePrintCopyInfo(); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + if ($registration->is_primary_registrant()) { |
|
158 | + // generate hidden input |
|
159 | + $form_args['subsections']['primary_registrant'] = $this->additionalPrimaryRegistrantInputs( |
|
160 | + $registration |
|
161 | + ); |
|
162 | + } |
|
163 | + } |
|
164 | + } |
|
165 | + $attendee_nmbr++; |
|
166 | + |
|
167 | + // Increment the reg forms number if form is valid. |
|
168 | + if (! empty($form_args)) { |
|
169 | + $this->has_questions = true; |
|
170 | + } |
|
171 | + |
|
172 | + return $form_args; |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * @param EE_Registration $registration |
|
178 | + * @return EE_Form_Input_Base |
|
179 | + * @throws EE_Error |
|
180 | + */ |
|
181 | + private function additionalAttendeeRegInfoInput(EE_Registration $registration) |
|
182 | + { |
|
183 | + // generate hidden input |
|
184 | + return new EE_Hidden_Input( |
|
185 | + [ |
|
186 | + 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
187 | + 'default' => true, |
|
188 | + ] |
|
189 | + ); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @param EE_Registration $registration |
|
195 | + * @return EE_Form_Input_Base |
|
196 | + * @throws EE_Error |
|
197 | + */ |
|
198 | + private function additionalPrimaryRegistrantInputs(EE_Registration $registration) |
|
199 | + { |
|
200 | + // generate hidden input |
|
201 | + return new EE_Hidden_Input( |
|
202 | + [ |
|
203 | + 'html_id' => 'primary_registrant', |
|
204 | + 'default' => $registration->reg_url_link(), |
|
205 | + ] |
|
206 | + ); |
|
207 | + } |
|
208 | 208 | } |
@@ -6,16 +6,16 @@ discard block |
||
6 | 6 | <?php if (!is_admin()) : ?> |
7 | 7 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
8 | 8 | <?php echo apply_filters( |
9 | - 'FHEE__registration_page_attendee_information__attendee_information_pg', |
|
10 | - sprintf( |
|
11 | - __( |
|
12 | - 'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', |
|
13 | - 'event_espresso' |
|
14 | - ), |
|
15 | - '<br />', |
|
16 | - '<span class="asterisk">*</span>' |
|
17 | - ) |
|
18 | - ); ?> |
|
9 | + 'FHEE__registration_page_attendee_information__attendee_information_pg', |
|
10 | + sprintf( |
|
11 | + __( |
|
12 | + 'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', |
|
13 | + 'event_espresso' |
|
14 | + ), |
|
15 | + '<br />', |
|
16 | + '<span class="asterisk">*</span>' |
|
17 | + ) |
|
18 | + ); ?> |
|
19 | 19 | </p> |
20 | 20 | <?php endif; ?> |
21 | 21 | |
@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | $prev_ticket = 0; |
26 | 26 | |
27 | 27 | if (count($registrations) > 0) { |
28 | - foreach ($registrations as $registration) { |
|
29 | - if ($registration instanceof EE_Registration) { |
|
30 | - $att_nmbr++; |
|
31 | - ?> |
|
28 | + foreach ($registrations as $registration) { |
|
29 | + if ($registration instanceof EE_Registration) { |
|
30 | + $att_nmbr++; |
|
31 | + ?> |
|
32 | 32 | |
33 | 33 | <div id="spco-attendee-panel-dv-<?php echo $registration->reg_url_link(); ?>" |
34 | 34 | class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo $registration->ticket()->ID(); ?>"> |
@@ -47,19 +47,19 @@ discard block |
||
47 | 47 | <th scope="col" width="" class="jst-left"></th> |
48 | 48 | <th scope="col" width="7.5%" class="jst-rght"> |
49 | 49 | <?php _e( |
50 | - 'Qty', |
|
51 | - 'event_espresso' |
|
52 | - ); ?></th> |
|
50 | + 'Qty', |
|
51 | + 'event_espresso' |
|
52 | + ); ?></th> |
|
53 | 53 | <th scope="col" width="17.5%" class="jst-rght"> |
54 | 54 | <?php _e( |
55 | - 'Price', |
|
56 | - 'event_espresso' |
|
57 | - ); ?></th> |
|
55 | + 'Price', |
|
56 | + 'event_espresso' |
|
57 | + ); ?></th> |
|
58 | 58 | <th scope="col" width="17.5%" class="jst-rght"> |
59 | 59 | <?php _e( |
60 | - 'Total', |
|
61 | - 'event_espresso' |
|
62 | - ); ?></th> |
|
60 | + 'Total', |
|
61 | + 'event_espresso' |
|
62 | + ); ?></th> |
|
63 | 63 | </tr> |
64 | 64 | </thead> |
65 | 65 | <tbody> |
@@ -71,19 +71,19 @@ discard block |
||
71 | 71 | <?php } ?> |
72 | 72 | |
73 | 73 | <?php |
74 | - // ATTENDEE QUESTIONS |
|
75 | - $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
76 | - echo ${$reg_form}; |
|
77 | - ?> |
|
74 | + // ATTENDEE QUESTIONS |
|
75 | + $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
76 | + echo ${$reg_form}; |
|
77 | + ?> |
|
78 | 78 | |
79 | 79 | </div> |
80 | 80 | <?php |
81 | - $prev_event = $registration->event()->ID(); |
|
82 | - $prev_ticket = $registration->ticket()->ID(); |
|
83 | - } // if ( $registration instanceof EE_Registration ) |
|
84 | - } // end foreach ( $registrations as $registration ) |
|
81 | + $prev_event = $registration->event()->ID(); |
|
82 | + $prev_ticket = $registration->ticket()->ID(); |
|
83 | + } // if ( $registration instanceof EE_Registration ) |
|
84 | + } // end foreach ( $registrations as $registration ) |
|
85 | 85 | |
86 | - echo $default_hidden_inputs; |
|
86 | + echo $default_hidden_inputs; |
|
87 | 87 | } // end if ( count( $registrations ) > 0 ) |
88 | 88 | |
89 | 89 | ?> |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | /** @var array $ticket_line_item */ |
4 | 4 | /** @var string $default_hidden_inputs */ |
5 | 5 | ?> |
6 | -<?php if (!is_admin()) : ?> |
|
6 | +<?php if ( ! is_admin()) : ?> |
|
7 | 7 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
8 | 8 | <?php echo apply_filters( |
9 | 9 | 'FHEE__registration_page_attendee_information__attendee_information_pg', |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | <div id="spco-attendee-panel-dv-<?php echo $registration->reg_url_link(); ?>" |
34 | 34 | class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo $registration->ticket()->ID(); ?>"> |
35 | 35 | |
36 | - <?php if (!is_admin() && $registration->event()->ID() !== $prev_event) { ?> |
|
36 | + <?php if ( ! is_admin() && $registration->event()->ID() !== $prev_event) { ?> |
|
37 | 37 | <h4 id="event_title-<?php echo $registration->event()->ID() ?>" class="big-event-title-hdr"> |
38 | 38 | <?php echo $registration->event()->name(); ?> |
39 | 39 | </h4> |
40 | 40 | <?php } ?> |
41 | 41 | <?php if ($registration->ticket()->ID() !== $prev_ticket) { ?> |
42 | - <?php if (! $revisit) { ?> |
|
42 | + <?php if ( ! $revisit) { ?> |
|
43 | 43 | <div class="spco-ticket-info-dv"> |
44 | 44 | <table class="spco-ticket-details"> |
45 | 45 | <thead> |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | </tr> |
64 | 64 | </thead> |
65 | 65 | <tbody> |
66 | - <?php echo $ticket_line_item[ $registration->ticket()->ID() ]; ?> |
|
66 | + <?php echo $ticket_line_item[$registration->ticket()->ID()]; ?> |
|
67 | 67 | </tbody> |
68 | 68 | </table> |
69 | 69 | </div> |
@@ -6,16 +6,16 @@ discard block |
||
6 | 6 | <?php if (!is_admin()) : ?> |
7 | 7 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
8 | 8 | <?php echo apply_filters( |
9 | - 'FHEE__registration_page_attendee_information__attendee_information_pg', |
|
10 | - sprintf( |
|
11 | - esc_html__( |
|
12 | - 'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', |
|
13 | - 'event_espresso' |
|
14 | - ), |
|
15 | - '<br />', |
|
16 | - '<span class="asterisk">*</span>' |
|
17 | - ) |
|
18 | - ); ?> |
|
9 | + 'FHEE__registration_page_attendee_information__attendee_information_pg', |
|
10 | + sprintf( |
|
11 | + esc_html__( |
|
12 | + 'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', |
|
13 | + 'event_espresso' |
|
14 | + ), |
|
15 | + '<br />', |
|
16 | + '<span class="asterisk">*</span>' |
|
17 | + ) |
|
18 | + ); ?> |
|
19 | 19 | </p> |
20 | 20 | <?php endif; ?> |
21 | 21 | |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | $prev_ticket = 0; |
26 | 26 | |
27 | 27 | if (count($registrations) > 0) { |
28 | - $ticketID = key($template_args['ticket_count']); |
|
29 | - ?> |
|
28 | + $ticketID = key($template_args['ticket_count']); |
|
29 | + ?> |
|
30 | 30 | |
31 | 31 | <div id="spco-attendee-panel-dv-<?php echo $ticketID; ?>" |
32 | 32 | class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo $ticketID; ?>"> |
@@ -38,54 +38,54 @@ discard block |
||
38 | 38 | <th scope="col" width="" class="jst-left"></th> |
39 | 39 | <th scope="col" width="7.5%" class="jst-rght"> |
40 | 40 | <?php esc_html_e( |
41 | - 'Qty', |
|
42 | - 'event_espresso' |
|
43 | - ); ?></th> |
|
41 | + 'Qty', |
|
42 | + 'event_espresso' |
|
43 | + ); ?></th> |
|
44 | 44 | <th scope="col" width="17.5%" class="jst-rght"> |
45 | 45 | <?php esc_html_e( |
46 | - 'Price', |
|
47 | - 'event_espresso' |
|
48 | - ); ?></th> |
|
46 | + 'Price', |
|
47 | + 'event_espresso' |
|
48 | + ); ?></th> |
|
49 | 49 | <th scope="col" width="17.5%" class="jst-rght"> |
50 | 50 | <?php esc_html_e( |
51 | - 'Total', |
|
52 | - 'event_espresso' |
|
53 | - ); ?></th> |
|
51 | + 'Total', |
|
52 | + 'event_espresso' |
|
53 | + ); ?></th> |
|
54 | 54 | </tr> |
55 | 55 | </thead> |
56 | 56 | <tbody> |
57 | 57 | <?php |
58 | - // Store previous values to avoid duplicated rows. |
|
59 | - $prev_ticket = 0; |
|
60 | - // Display all tickets inside. |
|
61 | - foreach ($registrations as $registration) { |
|
62 | - if ($registration instanceof EE_Registration) { |
|
63 | - if ($registration->ticket()->ID() !== $prev_ticket) { |
|
64 | - echo $ticket_line_item[ $registration->ticket()->ID() ]; |
|
65 | - } |
|
58 | + // Store previous values to avoid duplicated rows. |
|
59 | + $prev_ticket = 0; |
|
60 | + // Display all tickets inside. |
|
61 | + foreach ($registrations as $registration) { |
|
62 | + if ($registration instanceof EE_Registration) { |
|
63 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
64 | + echo $ticket_line_item[ $registration->ticket()->ID() ]; |
|
65 | + } |
|
66 | 66 | |
67 | - $prev_ticket = $registration->ticket()->ID(); |
|
68 | - } |
|
69 | - } |
|
70 | - ?> |
|
67 | + $prev_ticket = $registration->ticket()->ID(); |
|
68 | + } |
|
69 | + } |
|
70 | + ?> |
|
71 | 71 | </tbody> |
72 | 72 | </table> |
73 | 73 | </div><!-- close spco-ticket-info-dv --> |
74 | 74 | |
75 | 75 | <?php |
76 | - // Display the forms below the table. |
|
77 | - foreach ($registrations as $registration) { |
|
78 | - if ($registration instanceof EE_Registration) { |
|
79 | - // Attendee Questions. |
|
80 | - $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
81 | - echo ${$reg_form}; |
|
82 | - } // if ( $registration instanceof EE_Registration ) |
|
83 | - } // end foreach ( $registrations as $registration ) |
|
76 | + // Display the forms below the table. |
|
77 | + foreach ($registrations as $registration) { |
|
78 | + if ($registration instanceof EE_Registration) { |
|
79 | + // Attendee Questions. |
|
80 | + $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
81 | + echo ${$reg_form}; |
|
82 | + } // if ( $registration instanceof EE_Registration ) |
|
83 | + } // end foreach ( $registrations as $registration ) |
|
84 | 84 | |
85 | - ?> |
|
85 | + ?> |
|
86 | 86 | </div><!-- close spco-attendee-panel-dv --> |
87 | 87 | <?php |
88 | - echo $default_hidden_inputs; |
|
88 | + echo $default_hidden_inputs; |
|
89 | 89 | } // end if ( count( $registrations ) > 0 ) |
90 | 90 | |
91 | 91 | ?> |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | /** @var array $ticket_line_item */ |
4 | 4 | /** @var string $default_hidden_inputs */ |
5 | 5 | ?> |
6 | -<?php if (!is_admin()) : ?> |
|
6 | +<?php if ( ! is_admin()) : ?> |
|
7 | 7 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
8 | 8 | <?php echo apply_filters( |
9 | 9 | 'FHEE__registration_page_attendee_information__attendee_information_pg', |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | foreach ($registrations as $registration) { |
62 | 62 | if ($registration instanceof EE_Registration) { |
63 | 63 | if ($registration->ticket()->ID() !== $prev_ticket) { |
64 | - echo $ticket_line_item[ $registration->ticket()->ID() ]; |
|
64 | + echo $ticket_line_item[$registration->ticket()->ID()]; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | $prev_ticket = $registration->ticket()->ID(); |
@@ -13,688 +13,688 @@ |
||
13 | 13 | |
14 | 14 | // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
15 | 15 | if (! function_exists('mb_strcut')) { |
16 | - /** |
|
17 | - * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
18 | - * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
19 | - * @param $string |
|
20 | - * @param $start |
|
21 | - * @param $length |
|
22 | - * @return bool|string |
|
23 | - */ |
|
24 | - function mb_strcut($string, $start, $length = null) |
|
25 | - { |
|
26 | - return mb_substr($string, $start, $length); |
|
27 | - } |
|
16 | + /** |
|
17 | + * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
18 | + * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
19 | + * @param $string |
|
20 | + * @param $start |
|
21 | + * @param $length |
|
22 | + * @return bool|string |
|
23 | + */ |
|
24 | + function mb_strcut($string, $start, $length = null) |
|
25 | + { |
|
26 | + return mb_substr($string, $start, $length); |
|
27 | + } |
|
28 | 28 | } |
29 | 29 | class EEG_Paypal_Express extends EE_Offsite_Gateway |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * Merchant API Username. |
|
34 | - * |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - protected $_api_username; |
|
38 | - |
|
39 | - /** |
|
40 | - * Merchant API Password. |
|
41 | - * |
|
42 | - * @var string |
|
43 | - */ |
|
44 | - protected $_api_password; |
|
45 | - |
|
46 | - /** |
|
47 | - * API Signature. |
|
48 | - * |
|
49 | - * @var string |
|
50 | - */ |
|
51 | - protected $_api_signature; |
|
52 | - |
|
53 | - /** |
|
54 | - * Request Shipping address on PP checkout page. |
|
55 | - * |
|
56 | - * @var string |
|
57 | - */ |
|
58 | - protected $_request_shipping_addr; |
|
59 | - |
|
60 | - /** |
|
61 | - * Business/personal logo. |
|
62 | - * |
|
63 | - * @var string |
|
64 | - */ |
|
65 | - protected $_image_url; |
|
66 | - |
|
67 | - /** |
|
68 | - * gateway URL variable |
|
69 | - * |
|
70 | - * @var string |
|
71 | - */ |
|
72 | - protected $_base_gateway_url = ''; |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * number of decimal places to round numbers to when performing calculations |
|
77 | - * |
|
78 | - * @var integer |
|
79 | - */ |
|
80 | - protected $decimal_precision = 6; |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * EEG_Paypal_Express constructor. |
|
85 | - */ |
|
86 | - public function __construct() |
|
87 | - { |
|
88 | - $this->_currencies_supported = array( |
|
89 | - 'USD', |
|
90 | - 'AUD', |
|
91 | - 'BRL', |
|
92 | - 'CAD', |
|
93 | - 'CZK', |
|
94 | - 'DKK', |
|
95 | - 'EUR', |
|
96 | - 'HKD', |
|
97 | - 'HUF', |
|
98 | - 'ILS', |
|
99 | - 'JPY', |
|
100 | - 'MYR', |
|
101 | - 'MXN', |
|
102 | - 'NOK', |
|
103 | - 'NZD', |
|
104 | - 'PHP', |
|
105 | - 'PLN', |
|
106 | - 'GBP', |
|
107 | - 'RUB', |
|
108 | - 'SGD', |
|
109 | - 'SEK', |
|
110 | - 'CHF', |
|
111 | - 'TWD', |
|
112 | - 'THB', |
|
113 | - 'TRY', |
|
114 | - 'INR', |
|
115 | - ); |
|
116 | - parent::__construct(); |
|
117 | - $this->decimal_precision = EE_Registry::instance()->CFG->currency->dec_plc; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
124 | - * |
|
125 | - * @param array $settings_array |
|
126 | - */ |
|
127 | - public function set_settings($settings_array) |
|
128 | - { |
|
129 | - parent::set_settings($settings_array); |
|
130 | - // Redirect URL. |
|
131 | - $this->_base_gateway_url = $this->_debug_mode |
|
132 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
133 | - : 'https://api-3t.paypal.com/nvp'; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @param EEI_Payment $payment |
|
140 | - * @param array $billing_info |
|
141 | - * @param string $return_url |
|
142 | - * @param string $notify_url |
|
143 | - * @param string $cancel_url |
|
144 | - * @return \EE_Payment|\EEI_Payment |
|
145 | - * @throws \EE_Error |
|
146 | - */ |
|
147 | - public function set_redirection_info( |
|
148 | - $payment, |
|
149 | - $billing_info = array(), |
|
150 | - $return_url = null, |
|
151 | - $notify_url = null, |
|
152 | - $cancel_url = null |
|
153 | - ) { |
|
154 | - if (! $payment instanceof EEI_Payment) { |
|
155 | - $payment->set_gateway_response( |
|
156 | - esc_html__( |
|
157 | - 'Error. No associated payment was found.', |
|
158 | - 'event_espresso' |
|
159 | - ) |
|
160 | - ); |
|
161 | - $payment->set_status($this->_pay_model->failed_status()); |
|
162 | - return $payment; |
|
163 | - } |
|
164 | - $transaction = $payment->transaction(); |
|
165 | - if (! $transaction instanceof EEI_Transaction) { |
|
166 | - $payment->set_gateway_response( |
|
167 | - esc_html__( |
|
168 | - 'Could not process this payment because it has no associated transaction.', |
|
169 | - 'event_espresso' |
|
170 | - ) |
|
171 | - ); |
|
172 | - $payment->set_status($this->_pay_model->failed_status()); |
|
173 | - return $payment; |
|
174 | - } |
|
175 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
176 | - $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
177 | - $primary_registration = $transaction->primary_registration(); |
|
178 | - $primary_attendee = $primary_registration instanceof EE_Registration |
|
179 | - ? $primary_registration->attendee() |
|
180 | - : false; |
|
181 | - $locale = explode('-', get_bloginfo('language')); |
|
182 | - // Gather request parameters. |
|
183 | - $token_request_dtls = array( |
|
184 | - 'METHOD' => 'SetExpressCheckout', |
|
185 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
186 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
187 | - 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
188 | - 'RETURNURL' => $return_url, |
|
189 | - 'CANCELURL' => $cancel_url, |
|
190 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
191 | - // Buyer does not need to create a PayPal account to check out. |
|
192 | - // This is referred to as PayPal Account Optional. |
|
193 | - 'SOLUTIONTYPE' => 'Sole', |
|
194 | - // Locale of the pages displayed by PayPal during Express Checkout. |
|
195 | - 'LOCALECODE' => $locale[1] |
|
196 | - ); |
|
197 | - // Show itemized list. |
|
198 | - $itemized_list = $this->itemize_list($payment, $transaction); |
|
199 | - $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
200 | - // Automatically filling out shipping and contact information. |
|
201 | - if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
202 | - // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
203 | - $token_request_dtls['NOSHIPPING'] = '2'; |
|
204 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
205 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
206 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
207 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
208 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
209 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
210 | - $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
211 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
212 | - } elseif (! $this->_request_shipping_addr) { |
|
213 | - // Do not request shipping details on the PP Checkout page. |
|
214 | - $token_request_dtls['NOSHIPPING'] = '1'; |
|
215 | - $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
216 | - } |
|
217 | - // Used a business/personal logo on the PayPal page. |
|
218 | - if (! empty($this->_image_url)) { |
|
219 | - $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
220 | - } |
|
221 | - $token_request_dtls = apply_filters( |
|
222 | - 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
223 | - $token_request_dtls, |
|
224 | - $this |
|
225 | - ); |
|
226 | - // Request PayPal token. |
|
227 | - $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
228 | - $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
229 | - $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
230 | - ? $token_rstatus['args'] |
|
231 | - : array(); |
|
232 | - if ($token_rstatus['status']) { |
|
233 | - // We got the Token so we may continue with the payment and redirect the client. |
|
234 | - $payment->set_details($response_args); |
|
235 | - $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
236 | - $payment->set_redirect_url( |
|
237 | - $gateway_url |
|
238 | - . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
239 | - . $response_args['TOKEN'] |
|
240 | - ); |
|
241 | - } else { |
|
242 | - if (isset($response_args['L_ERRORCODE'])) { |
|
243 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
244 | - } else { |
|
245 | - $payment->set_gateway_response( |
|
246 | - esc_html__( |
|
247 | - 'Error occurred while trying to setup the Express Checkout.', |
|
248 | - 'event_espresso' |
|
249 | - ) |
|
250 | - ); |
|
251 | - } |
|
252 | - $payment->set_details($response_args); |
|
253 | - $payment->set_status($this->_pay_model->failed_status()); |
|
254 | - } |
|
255 | - return $payment; |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * @param array $update_info { |
|
262 | - * @type string $gateway_txn_id |
|
263 | - * @type string status an EEMI_Payment status |
|
264 | - * } |
|
265 | - * @param EEI_Transaction $transaction |
|
266 | - * @return EEI_Payment |
|
267 | - */ |
|
268 | - public function handle_payment_update($update_info, $transaction) |
|
269 | - { |
|
270 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
271 | - if ($payment instanceof EEI_Payment) { |
|
272 | - $this->log(array('Return from Authorization' => $update_info), $payment); |
|
273 | - $transaction = $payment->transaction(); |
|
274 | - if (! $transaction instanceof EEI_Transaction) { |
|
275 | - $payment->set_gateway_response( |
|
276 | - esc_html__( |
|
277 | - 'Could not process this payment because it has no associated transaction.', |
|
278 | - 'event_espresso' |
|
279 | - ) |
|
280 | - ); |
|
281 | - $payment->set_status($this->_pay_model->failed_status()); |
|
282 | - return $payment; |
|
283 | - } |
|
284 | - $primary_registrant = $transaction->primary_registration(); |
|
285 | - $payment_details = $payment->details(); |
|
286 | - // Check if we still have the token. |
|
287 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
288 | - $payment->set_status($this->_pay_model->failed_status()); |
|
289 | - return $payment; |
|
290 | - } |
|
291 | - $cdetails_request_dtls = array( |
|
292 | - 'METHOD' => 'GetExpressCheckoutDetails', |
|
293 | - 'TOKEN' => $payment_details['TOKEN'], |
|
294 | - ); |
|
295 | - // Request Customer Details. |
|
296 | - $cdetails_request_response = $this->_ppExpress_request( |
|
297 | - $cdetails_request_dtls, |
|
298 | - 'Customer Details', |
|
299 | - $payment |
|
300 | - ); |
|
301 | - $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
302 | - $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
303 | - ? $cdetails_rstatus['args'] |
|
304 | - : array(); |
|
305 | - if ($cdetails_rstatus['status']) { |
|
306 | - // We got the PayerID so now we can Complete the transaction. |
|
307 | - $docheckout_request_dtls = array( |
|
308 | - 'METHOD' => 'DoExpressCheckoutPayment', |
|
309 | - 'PAYERID' => $cdata_response_args['PAYERID'], |
|
310 | - 'TOKEN' => $payment_details['TOKEN'], |
|
311 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
312 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
313 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
314 | - ); |
|
315 | - // Include itemized list. |
|
316 | - $itemized_list = $this->itemize_list( |
|
317 | - $payment, |
|
318 | - $transaction, |
|
319 | - $cdata_response_args |
|
320 | - ); |
|
321 | - $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
322 | - // Payment Checkout/Capture. |
|
323 | - $docheckout_request_response = $this->_ppExpress_request( |
|
324 | - $docheckout_request_dtls, |
|
325 | - 'Do Payment', |
|
326 | - $payment |
|
327 | - ); |
|
328 | - $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
329 | - $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
330 | - ? $docheckout_rstatus['args'] |
|
331 | - : array(); |
|
332 | - if ($docheckout_rstatus['status']) { |
|
333 | - // All is well, payment approved. |
|
334 | - $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
335 | - $primary_registrant->reg_code() |
|
336 | - : ''; |
|
337 | - $payment->set_extra_accntng($primary_registration_code); |
|
338 | - $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
339 | - ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
340 | - : 0); |
|
341 | - $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
342 | - ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
343 | - : null); |
|
344 | - $payment->set_details($cdata_response_args); |
|
345 | - $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
346 | - ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
347 | - : ''); |
|
348 | - $payment->set_status($this->_pay_model->approved_status()); |
|
349 | - } else { |
|
350 | - if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
351 | - $payment->set_gateway_response( |
|
352 | - $docheckout_response_args['L_ERRORCODE'] |
|
353 | - . '; ' |
|
354 | - . $docheckout_response_args['L_SHORTMESSAGE'] |
|
355 | - ); |
|
356 | - } else { |
|
357 | - $payment->set_gateway_response( |
|
358 | - esc_html__( |
|
359 | - 'Error occurred while trying to Capture the funds.', |
|
360 | - 'event_espresso' |
|
361 | - ) |
|
362 | - ); |
|
363 | - } |
|
364 | - $payment->set_details($docheckout_response_args); |
|
365 | - $payment->set_status($this->_pay_model->declined_status()); |
|
366 | - } |
|
367 | - } else { |
|
368 | - if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
369 | - $payment->set_gateway_response( |
|
370 | - $cdata_response_args['L_ERRORCODE'] |
|
371 | - . '; ' |
|
372 | - . $cdata_response_args['L_SHORTMESSAGE'] |
|
373 | - ); |
|
374 | - } else { |
|
375 | - $payment->set_gateway_response( |
|
376 | - esc_html__( |
|
377 | - 'Error occurred while trying to get payment Details from PayPal.', |
|
378 | - 'event_espresso' |
|
379 | - ) |
|
380 | - ); |
|
381 | - } |
|
382 | - $payment->set_details($cdata_response_args); |
|
383 | - $payment->set_status($this->_pay_model->failed_status()); |
|
384 | - } |
|
385 | - } else { |
|
386 | - $payment->set_gateway_response( |
|
387 | - esc_html__( |
|
388 | - 'Error occurred while trying to process the payment.', |
|
389 | - 'event_espresso' |
|
390 | - ) |
|
391 | - ); |
|
392 | - $payment->set_status($this->_pay_model->failed_status()); |
|
393 | - } |
|
394 | - return $payment; |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - |
|
399 | - /** |
|
400 | - * Make a list of items that are in the giver transaction. |
|
401 | - * |
|
402 | - * @param EEI_Payment $payment |
|
403 | - * @param EEI_Transaction $transaction |
|
404 | - * @param array $request_response_args Data from a previous communication with PP. |
|
405 | - * @return array |
|
406 | - */ |
|
407 | - public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
408 | - { |
|
409 | - $itemized_list = array(); |
|
410 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
411 | - // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
412 | - if ( |
|
413 | - ! empty($request_response_args) |
|
414 | - && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
415 | - && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
416 | - ) { |
|
417 | - foreach ($request_response_args as $arg_key => $arg_val) { |
|
418 | - if ( |
|
419 | - strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
420 | - && strpos($arg_key, 'NOTIFYURL') === false |
|
421 | - ) { |
|
422 | - $itemized_list[ $arg_key ] = $arg_val; |
|
423 | - } |
|
424 | - } |
|
425 | - // If we got only a few Items then something is not right. |
|
426 | - if (count($itemized_list) > 2) { |
|
427 | - return $itemized_list; |
|
428 | - } else { |
|
429 | - if (WP_DEBUG) { |
|
430 | - throw new EE_Error( |
|
431 | - sprintf( |
|
432 | - esc_html__( |
|
433 | - // @codingStandardsIgnoreStart |
|
434 | - 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
435 | - // @codingStandardsIgnoreEnd |
|
436 | - 'event_espresso' |
|
437 | - ), |
|
438 | - wp_json_encode($itemized_list) |
|
439 | - ) |
|
440 | - ); |
|
441 | - } |
|
442 | - // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
443 | - $itemized_list = array(); |
|
444 | - $this->log( |
|
445 | - array( |
|
446 | - (string) esc_html__( |
|
447 | - 'Could not generate a proper item list with:', |
|
448 | - 'event_espresso' |
|
449 | - ) => $request_response_args |
|
450 | - ), |
|
451 | - $payment |
|
452 | - ); |
|
453 | - } |
|
454 | - } |
|
455 | - // ...otherwise we generate a new list for this transaction. |
|
456 | - if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
457 | - $item_num = 0; |
|
458 | - $itemized_sum = 0; |
|
459 | - $total_line_items = $transaction->total_line_item(); |
|
460 | - // Go through each item in the list. |
|
461 | - foreach ($total_line_items->get_items() as $line_item) { |
|
462 | - if ($line_item instanceof EE_Line_Item) { |
|
463 | - // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
464 | - if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
465 | - continue; |
|
466 | - } |
|
467 | - $unit_price = $line_item->unit_price(); |
|
468 | - $line_item_quantity = $line_item->quantity(); |
|
469 | - // This is a discount. |
|
470 | - if ($line_item->is_percent()) { |
|
471 | - $unit_price = $line_item->total(); |
|
472 | - $line_item_quantity = 1; |
|
473 | - } |
|
474 | - // Item Name. |
|
475 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
476 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
477 | - 0, |
|
478 | - 127 |
|
479 | - ); |
|
480 | - // Item description. |
|
481 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
482 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
483 | - 0, |
|
484 | - 127 |
|
485 | - ); |
|
486 | - // Cost of individual item. |
|
487 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
488 | - $unit_price, |
|
489 | - $this->decimal_precision |
|
490 | - ); |
|
491 | - // Item Number. |
|
492 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
493 | - // Item quantity. |
|
494 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
495 | - // Digital item is sold. |
|
496 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
497 | - $itemized_sum += $line_item->total(); |
|
498 | - ++$item_num; |
|
499 | - } |
|
500 | - } |
|
501 | - // Item's sales S/H and tax amount. |
|
502 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
503 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
504 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
505 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
506 | - $itemized_sum_diff_from_txn_total = round( |
|
507 | - $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
508 | - $this->decimal_precision |
|
509 | - ); |
|
510 | - // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
511 | - // add the difference as an extra line item. |
|
512 | - if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
513 | - // Item Name. |
|
514 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
515 | - esc_html__( |
|
516 | - 'Other (promotion/surcharge/cancellation)', |
|
517 | - 'event_espresso' |
|
518 | - ), |
|
519 | - 0, |
|
520 | - 127 |
|
521 | - ); |
|
522 | - // Item description. |
|
523 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
524 | - // Cost of individual item. |
|
525 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
526 | - $itemized_sum_diff_from_txn_total |
|
527 | - ); |
|
528 | - // Item Number. |
|
529 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
530 | - // Item quantity. |
|
531 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
532 | - // Digital item is sold. |
|
533 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
534 | - $item_num++; |
|
535 | - } |
|
536 | - } else { |
|
537 | - // Just one Item. |
|
538 | - // Item Name. |
|
539 | - $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
540 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
541 | - 0, |
|
542 | - 127 |
|
543 | - ); |
|
544 | - // Item description. |
|
545 | - $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
546 | - $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
547 | - 0, |
|
548 | - 127 |
|
549 | - ); |
|
550 | - // Cost of individual item. |
|
551 | - $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
552 | - // Item Number. |
|
553 | - $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
554 | - // Item quantity. |
|
555 | - $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
556 | - // Digital item is sold. |
|
557 | - $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
558 | - // Item's sales S/H and tax amount. |
|
559 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
560 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
561 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
562 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
563 | - } |
|
564 | - return $itemized_list; |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - |
|
569 | - /** |
|
570 | - * Make the Express checkout request. |
|
571 | - * |
|
572 | - * @param array $request_params |
|
573 | - * @param string $request_text |
|
574 | - * @param EEI_Payment $payment |
|
575 | - * @return mixed |
|
576 | - */ |
|
577 | - public function _ppExpress_request($request_params, $request_text, $payment) |
|
578 | - { |
|
579 | - $request_dtls = array( |
|
580 | - 'VERSION' => '204.0', |
|
581 | - 'USER' => $this->_api_username, |
|
582 | - 'PWD' => $this->_api_password, |
|
583 | - 'SIGNATURE' => $this->_api_signature, |
|
584 | - // EE will blow up if you change this |
|
585 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
586 | - ); |
|
587 | - $dtls = array_merge($request_dtls, $request_params); |
|
588 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
589 | - // Request Customer Details. |
|
590 | - $request_response = wp_remote_post( |
|
591 | - $this->_base_gateway_url, |
|
592 | - array( |
|
593 | - 'method' => 'POST', |
|
594 | - 'timeout' => 45, |
|
595 | - 'httpversion' => '1.1', |
|
596 | - 'cookies' => array(), |
|
597 | - 'headers' => array(), |
|
598 | - 'body' => http_build_query($dtls, '', '&'), |
|
599 | - ) |
|
600 | - ); |
|
601 | - // Log the response. |
|
602 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
603 | - return $request_response; |
|
604 | - } |
|
605 | - |
|
606 | - |
|
607 | - |
|
608 | - /** |
|
609 | - * Check the response status. |
|
610 | - * |
|
611 | - * @param mixed $request_response |
|
612 | - * @return array |
|
613 | - */ |
|
614 | - public function _ppExpress_check_response($request_response) |
|
615 | - { |
|
616 | - if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
617 | - // If we got here then there was an error in this request. |
|
618 | - return array('status' => false, 'args' => $request_response); |
|
619 | - } |
|
620 | - $response_args = array(); |
|
621 | - parse_str(urldecode($request_response['body']), $response_args); |
|
622 | - if (! isset($response_args['ACK'])) { |
|
623 | - return array('status' => false, 'args' => $request_response); |
|
624 | - } |
|
625 | - if ( |
|
626 | - ( |
|
627 | - isset($response_args['PAYERID']) |
|
628 | - || isset($response_args['TOKEN']) |
|
629 | - || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
630 | - || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
631 | - ) |
|
632 | - && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
633 | - ) { |
|
634 | - // Response status OK, return response parameters for further processing. |
|
635 | - return array('status' => true, 'args' => $response_args); |
|
636 | - } |
|
637 | - $errors = $this->_get_errors($response_args); |
|
638 | - return array('status' => false, 'args' => $errors); |
|
639 | - } |
|
640 | - |
|
641 | - |
|
642 | - |
|
643 | - /** |
|
644 | - * Log a "Cleared" request. |
|
645 | - * |
|
646 | - * @param array $request |
|
647 | - * @param EEI_Payment $payment |
|
648 | - * @param string $info |
|
649 | - * @return void |
|
650 | - */ |
|
651 | - private function _log_clean_request($request, $payment, $info) |
|
652 | - { |
|
653 | - $cleaned_request_data = $request; |
|
654 | - unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
655 | - $this->log(array($info => $cleaned_request_data), $payment); |
|
656 | - } |
|
657 | - |
|
658 | - |
|
659 | - |
|
660 | - /** |
|
661 | - * Get error from the response data. |
|
662 | - * |
|
663 | - * @param array $data_array |
|
664 | - * @return array |
|
665 | - */ |
|
666 | - private function _get_errors($data_array) |
|
667 | - { |
|
668 | - $errors = array(); |
|
669 | - $n = 0; |
|
670 | - while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
671 | - $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
672 | - ? $data_array[ "L_ERRORCODE{$n}" ] |
|
673 | - : ''; |
|
674 | - $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
675 | - ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
676 | - : ''; |
|
677 | - $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
678 | - ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
679 | - : ''; |
|
680 | - $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
681 | - ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
682 | - : ''; |
|
683 | - if ($n === 0) { |
|
684 | - $errors = array( |
|
685 | - 'L_ERRORCODE' => $l_error_code, |
|
686 | - 'L_SHORTMESSAGE' => $l_short_message, |
|
687 | - 'L_LONGMESSAGE' => $l_long_message, |
|
688 | - 'L_SEVERITYCODE' => $l_severity_code, |
|
689 | - ); |
|
690 | - } else { |
|
691 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
692 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
693 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
694 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
695 | - } |
|
696 | - $n++; |
|
697 | - } |
|
698 | - return $errors; |
|
699 | - } |
|
32 | + /** |
|
33 | + * Merchant API Username. |
|
34 | + * |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + protected $_api_username; |
|
38 | + |
|
39 | + /** |
|
40 | + * Merchant API Password. |
|
41 | + * |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + protected $_api_password; |
|
45 | + |
|
46 | + /** |
|
47 | + * API Signature. |
|
48 | + * |
|
49 | + * @var string |
|
50 | + */ |
|
51 | + protected $_api_signature; |
|
52 | + |
|
53 | + /** |
|
54 | + * Request Shipping address on PP checkout page. |
|
55 | + * |
|
56 | + * @var string |
|
57 | + */ |
|
58 | + protected $_request_shipping_addr; |
|
59 | + |
|
60 | + /** |
|
61 | + * Business/personal logo. |
|
62 | + * |
|
63 | + * @var string |
|
64 | + */ |
|
65 | + protected $_image_url; |
|
66 | + |
|
67 | + /** |
|
68 | + * gateway URL variable |
|
69 | + * |
|
70 | + * @var string |
|
71 | + */ |
|
72 | + protected $_base_gateway_url = ''; |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * number of decimal places to round numbers to when performing calculations |
|
77 | + * |
|
78 | + * @var integer |
|
79 | + */ |
|
80 | + protected $decimal_precision = 6; |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * EEG_Paypal_Express constructor. |
|
85 | + */ |
|
86 | + public function __construct() |
|
87 | + { |
|
88 | + $this->_currencies_supported = array( |
|
89 | + 'USD', |
|
90 | + 'AUD', |
|
91 | + 'BRL', |
|
92 | + 'CAD', |
|
93 | + 'CZK', |
|
94 | + 'DKK', |
|
95 | + 'EUR', |
|
96 | + 'HKD', |
|
97 | + 'HUF', |
|
98 | + 'ILS', |
|
99 | + 'JPY', |
|
100 | + 'MYR', |
|
101 | + 'MXN', |
|
102 | + 'NOK', |
|
103 | + 'NZD', |
|
104 | + 'PHP', |
|
105 | + 'PLN', |
|
106 | + 'GBP', |
|
107 | + 'RUB', |
|
108 | + 'SGD', |
|
109 | + 'SEK', |
|
110 | + 'CHF', |
|
111 | + 'TWD', |
|
112 | + 'THB', |
|
113 | + 'TRY', |
|
114 | + 'INR', |
|
115 | + ); |
|
116 | + parent::__construct(); |
|
117 | + $this->decimal_precision = EE_Registry::instance()->CFG->currency->dec_plc; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
124 | + * |
|
125 | + * @param array $settings_array |
|
126 | + */ |
|
127 | + public function set_settings($settings_array) |
|
128 | + { |
|
129 | + parent::set_settings($settings_array); |
|
130 | + // Redirect URL. |
|
131 | + $this->_base_gateway_url = $this->_debug_mode |
|
132 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
133 | + : 'https://api-3t.paypal.com/nvp'; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @param EEI_Payment $payment |
|
140 | + * @param array $billing_info |
|
141 | + * @param string $return_url |
|
142 | + * @param string $notify_url |
|
143 | + * @param string $cancel_url |
|
144 | + * @return \EE_Payment|\EEI_Payment |
|
145 | + * @throws \EE_Error |
|
146 | + */ |
|
147 | + public function set_redirection_info( |
|
148 | + $payment, |
|
149 | + $billing_info = array(), |
|
150 | + $return_url = null, |
|
151 | + $notify_url = null, |
|
152 | + $cancel_url = null |
|
153 | + ) { |
|
154 | + if (! $payment instanceof EEI_Payment) { |
|
155 | + $payment->set_gateway_response( |
|
156 | + esc_html__( |
|
157 | + 'Error. No associated payment was found.', |
|
158 | + 'event_espresso' |
|
159 | + ) |
|
160 | + ); |
|
161 | + $payment->set_status($this->_pay_model->failed_status()); |
|
162 | + return $payment; |
|
163 | + } |
|
164 | + $transaction = $payment->transaction(); |
|
165 | + if (! $transaction instanceof EEI_Transaction) { |
|
166 | + $payment->set_gateway_response( |
|
167 | + esc_html__( |
|
168 | + 'Could not process this payment because it has no associated transaction.', |
|
169 | + 'event_espresso' |
|
170 | + ) |
|
171 | + ); |
|
172 | + $payment->set_status($this->_pay_model->failed_status()); |
|
173 | + return $payment; |
|
174 | + } |
|
175 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
176 | + $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
177 | + $primary_registration = $transaction->primary_registration(); |
|
178 | + $primary_attendee = $primary_registration instanceof EE_Registration |
|
179 | + ? $primary_registration->attendee() |
|
180 | + : false; |
|
181 | + $locale = explode('-', get_bloginfo('language')); |
|
182 | + // Gather request parameters. |
|
183 | + $token_request_dtls = array( |
|
184 | + 'METHOD' => 'SetExpressCheckout', |
|
185 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
186 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
187 | + 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
188 | + 'RETURNURL' => $return_url, |
|
189 | + 'CANCELURL' => $cancel_url, |
|
190 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
191 | + // Buyer does not need to create a PayPal account to check out. |
|
192 | + // This is referred to as PayPal Account Optional. |
|
193 | + 'SOLUTIONTYPE' => 'Sole', |
|
194 | + // Locale of the pages displayed by PayPal during Express Checkout. |
|
195 | + 'LOCALECODE' => $locale[1] |
|
196 | + ); |
|
197 | + // Show itemized list. |
|
198 | + $itemized_list = $this->itemize_list($payment, $transaction); |
|
199 | + $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
200 | + // Automatically filling out shipping and contact information. |
|
201 | + if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
202 | + // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
203 | + $token_request_dtls['NOSHIPPING'] = '2'; |
|
204 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
205 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
206 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
207 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
208 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
209 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
210 | + $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
211 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
212 | + } elseif (! $this->_request_shipping_addr) { |
|
213 | + // Do not request shipping details on the PP Checkout page. |
|
214 | + $token_request_dtls['NOSHIPPING'] = '1'; |
|
215 | + $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
216 | + } |
|
217 | + // Used a business/personal logo on the PayPal page. |
|
218 | + if (! empty($this->_image_url)) { |
|
219 | + $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
220 | + } |
|
221 | + $token_request_dtls = apply_filters( |
|
222 | + 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
223 | + $token_request_dtls, |
|
224 | + $this |
|
225 | + ); |
|
226 | + // Request PayPal token. |
|
227 | + $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
228 | + $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
229 | + $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
230 | + ? $token_rstatus['args'] |
|
231 | + : array(); |
|
232 | + if ($token_rstatus['status']) { |
|
233 | + // We got the Token so we may continue with the payment and redirect the client. |
|
234 | + $payment->set_details($response_args); |
|
235 | + $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
236 | + $payment->set_redirect_url( |
|
237 | + $gateway_url |
|
238 | + . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
239 | + . $response_args['TOKEN'] |
|
240 | + ); |
|
241 | + } else { |
|
242 | + if (isset($response_args['L_ERRORCODE'])) { |
|
243 | + $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
244 | + } else { |
|
245 | + $payment->set_gateway_response( |
|
246 | + esc_html__( |
|
247 | + 'Error occurred while trying to setup the Express Checkout.', |
|
248 | + 'event_espresso' |
|
249 | + ) |
|
250 | + ); |
|
251 | + } |
|
252 | + $payment->set_details($response_args); |
|
253 | + $payment->set_status($this->_pay_model->failed_status()); |
|
254 | + } |
|
255 | + return $payment; |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * @param array $update_info { |
|
262 | + * @type string $gateway_txn_id |
|
263 | + * @type string status an EEMI_Payment status |
|
264 | + * } |
|
265 | + * @param EEI_Transaction $transaction |
|
266 | + * @return EEI_Payment |
|
267 | + */ |
|
268 | + public function handle_payment_update($update_info, $transaction) |
|
269 | + { |
|
270 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
271 | + if ($payment instanceof EEI_Payment) { |
|
272 | + $this->log(array('Return from Authorization' => $update_info), $payment); |
|
273 | + $transaction = $payment->transaction(); |
|
274 | + if (! $transaction instanceof EEI_Transaction) { |
|
275 | + $payment->set_gateway_response( |
|
276 | + esc_html__( |
|
277 | + 'Could not process this payment because it has no associated transaction.', |
|
278 | + 'event_espresso' |
|
279 | + ) |
|
280 | + ); |
|
281 | + $payment->set_status($this->_pay_model->failed_status()); |
|
282 | + return $payment; |
|
283 | + } |
|
284 | + $primary_registrant = $transaction->primary_registration(); |
|
285 | + $payment_details = $payment->details(); |
|
286 | + // Check if we still have the token. |
|
287 | + if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
288 | + $payment->set_status($this->_pay_model->failed_status()); |
|
289 | + return $payment; |
|
290 | + } |
|
291 | + $cdetails_request_dtls = array( |
|
292 | + 'METHOD' => 'GetExpressCheckoutDetails', |
|
293 | + 'TOKEN' => $payment_details['TOKEN'], |
|
294 | + ); |
|
295 | + // Request Customer Details. |
|
296 | + $cdetails_request_response = $this->_ppExpress_request( |
|
297 | + $cdetails_request_dtls, |
|
298 | + 'Customer Details', |
|
299 | + $payment |
|
300 | + ); |
|
301 | + $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
302 | + $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
303 | + ? $cdetails_rstatus['args'] |
|
304 | + : array(); |
|
305 | + if ($cdetails_rstatus['status']) { |
|
306 | + // We got the PayerID so now we can Complete the transaction. |
|
307 | + $docheckout_request_dtls = array( |
|
308 | + 'METHOD' => 'DoExpressCheckoutPayment', |
|
309 | + 'PAYERID' => $cdata_response_args['PAYERID'], |
|
310 | + 'TOKEN' => $payment_details['TOKEN'], |
|
311 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
312 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
313 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
314 | + ); |
|
315 | + // Include itemized list. |
|
316 | + $itemized_list = $this->itemize_list( |
|
317 | + $payment, |
|
318 | + $transaction, |
|
319 | + $cdata_response_args |
|
320 | + ); |
|
321 | + $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
322 | + // Payment Checkout/Capture. |
|
323 | + $docheckout_request_response = $this->_ppExpress_request( |
|
324 | + $docheckout_request_dtls, |
|
325 | + 'Do Payment', |
|
326 | + $payment |
|
327 | + ); |
|
328 | + $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
329 | + $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
330 | + ? $docheckout_rstatus['args'] |
|
331 | + : array(); |
|
332 | + if ($docheckout_rstatus['status']) { |
|
333 | + // All is well, payment approved. |
|
334 | + $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
335 | + $primary_registrant->reg_code() |
|
336 | + : ''; |
|
337 | + $payment->set_extra_accntng($primary_registration_code); |
|
338 | + $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
339 | + ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
340 | + : 0); |
|
341 | + $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
342 | + ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
343 | + : null); |
|
344 | + $payment->set_details($cdata_response_args); |
|
345 | + $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
346 | + ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
347 | + : ''); |
|
348 | + $payment->set_status($this->_pay_model->approved_status()); |
|
349 | + } else { |
|
350 | + if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
351 | + $payment->set_gateway_response( |
|
352 | + $docheckout_response_args['L_ERRORCODE'] |
|
353 | + . '; ' |
|
354 | + . $docheckout_response_args['L_SHORTMESSAGE'] |
|
355 | + ); |
|
356 | + } else { |
|
357 | + $payment->set_gateway_response( |
|
358 | + esc_html__( |
|
359 | + 'Error occurred while trying to Capture the funds.', |
|
360 | + 'event_espresso' |
|
361 | + ) |
|
362 | + ); |
|
363 | + } |
|
364 | + $payment->set_details($docheckout_response_args); |
|
365 | + $payment->set_status($this->_pay_model->declined_status()); |
|
366 | + } |
|
367 | + } else { |
|
368 | + if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
369 | + $payment->set_gateway_response( |
|
370 | + $cdata_response_args['L_ERRORCODE'] |
|
371 | + . '; ' |
|
372 | + . $cdata_response_args['L_SHORTMESSAGE'] |
|
373 | + ); |
|
374 | + } else { |
|
375 | + $payment->set_gateway_response( |
|
376 | + esc_html__( |
|
377 | + 'Error occurred while trying to get payment Details from PayPal.', |
|
378 | + 'event_espresso' |
|
379 | + ) |
|
380 | + ); |
|
381 | + } |
|
382 | + $payment->set_details($cdata_response_args); |
|
383 | + $payment->set_status($this->_pay_model->failed_status()); |
|
384 | + } |
|
385 | + } else { |
|
386 | + $payment->set_gateway_response( |
|
387 | + esc_html__( |
|
388 | + 'Error occurred while trying to process the payment.', |
|
389 | + 'event_espresso' |
|
390 | + ) |
|
391 | + ); |
|
392 | + $payment->set_status($this->_pay_model->failed_status()); |
|
393 | + } |
|
394 | + return $payment; |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + |
|
399 | + /** |
|
400 | + * Make a list of items that are in the giver transaction. |
|
401 | + * |
|
402 | + * @param EEI_Payment $payment |
|
403 | + * @param EEI_Transaction $transaction |
|
404 | + * @param array $request_response_args Data from a previous communication with PP. |
|
405 | + * @return array |
|
406 | + */ |
|
407 | + public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
408 | + { |
|
409 | + $itemized_list = array(); |
|
410 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
411 | + // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
412 | + if ( |
|
413 | + ! empty($request_response_args) |
|
414 | + && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
415 | + && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
416 | + ) { |
|
417 | + foreach ($request_response_args as $arg_key => $arg_val) { |
|
418 | + if ( |
|
419 | + strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
420 | + && strpos($arg_key, 'NOTIFYURL') === false |
|
421 | + ) { |
|
422 | + $itemized_list[ $arg_key ] = $arg_val; |
|
423 | + } |
|
424 | + } |
|
425 | + // If we got only a few Items then something is not right. |
|
426 | + if (count($itemized_list) > 2) { |
|
427 | + return $itemized_list; |
|
428 | + } else { |
|
429 | + if (WP_DEBUG) { |
|
430 | + throw new EE_Error( |
|
431 | + sprintf( |
|
432 | + esc_html__( |
|
433 | + // @codingStandardsIgnoreStart |
|
434 | + 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
435 | + // @codingStandardsIgnoreEnd |
|
436 | + 'event_espresso' |
|
437 | + ), |
|
438 | + wp_json_encode($itemized_list) |
|
439 | + ) |
|
440 | + ); |
|
441 | + } |
|
442 | + // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
443 | + $itemized_list = array(); |
|
444 | + $this->log( |
|
445 | + array( |
|
446 | + (string) esc_html__( |
|
447 | + 'Could not generate a proper item list with:', |
|
448 | + 'event_espresso' |
|
449 | + ) => $request_response_args |
|
450 | + ), |
|
451 | + $payment |
|
452 | + ); |
|
453 | + } |
|
454 | + } |
|
455 | + // ...otherwise we generate a new list for this transaction. |
|
456 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
457 | + $item_num = 0; |
|
458 | + $itemized_sum = 0; |
|
459 | + $total_line_items = $transaction->total_line_item(); |
|
460 | + // Go through each item in the list. |
|
461 | + foreach ($total_line_items->get_items() as $line_item) { |
|
462 | + if ($line_item instanceof EE_Line_Item) { |
|
463 | + // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
464 | + if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
465 | + continue; |
|
466 | + } |
|
467 | + $unit_price = $line_item->unit_price(); |
|
468 | + $line_item_quantity = $line_item->quantity(); |
|
469 | + // This is a discount. |
|
470 | + if ($line_item->is_percent()) { |
|
471 | + $unit_price = $line_item->total(); |
|
472 | + $line_item_quantity = 1; |
|
473 | + } |
|
474 | + // Item Name. |
|
475 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
476 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
477 | + 0, |
|
478 | + 127 |
|
479 | + ); |
|
480 | + // Item description. |
|
481 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
482 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
483 | + 0, |
|
484 | + 127 |
|
485 | + ); |
|
486 | + // Cost of individual item. |
|
487 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
488 | + $unit_price, |
|
489 | + $this->decimal_precision |
|
490 | + ); |
|
491 | + // Item Number. |
|
492 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
493 | + // Item quantity. |
|
494 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
495 | + // Digital item is sold. |
|
496 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
497 | + $itemized_sum += $line_item->total(); |
|
498 | + ++$item_num; |
|
499 | + } |
|
500 | + } |
|
501 | + // Item's sales S/H and tax amount. |
|
502 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
503 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
504 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
505 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
506 | + $itemized_sum_diff_from_txn_total = round( |
|
507 | + $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
508 | + $this->decimal_precision |
|
509 | + ); |
|
510 | + // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
511 | + // add the difference as an extra line item. |
|
512 | + if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
513 | + // Item Name. |
|
514 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
515 | + esc_html__( |
|
516 | + 'Other (promotion/surcharge/cancellation)', |
|
517 | + 'event_espresso' |
|
518 | + ), |
|
519 | + 0, |
|
520 | + 127 |
|
521 | + ); |
|
522 | + // Item description. |
|
523 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
524 | + // Cost of individual item. |
|
525 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
526 | + $itemized_sum_diff_from_txn_total |
|
527 | + ); |
|
528 | + // Item Number. |
|
529 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
530 | + // Item quantity. |
|
531 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
532 | + // Digital item is sold. |
|
533 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
534 | + $item_num++; |
|
535 | + } |
|
536 | + } else { |
|
537 | + // Just one Item. |
|
538 | + // Item Name. |
|
539 | + $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
540 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
541 | + 0, |
|
542 | + 127 |
|
543 | + ); |
|
544 | + // Item description. |
|
545 | + $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
546 | + $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
547 | + 0, |
|
548 | + 127 |
|
549 | + ); |
|
550 | + // Cost of individual item. |
|
551 | + $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
552 | + // Item Number. |
|
553 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
554 | + // Item quantity. |
|
555 | + $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
556 | + // Digital item is sold. |
|
557 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
558 | + // Item's sales S/H and tax amount. |
|
559 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
560 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
561 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
562 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
563 | + } |
|
564 | + return $itemized_list; |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + |
|
569 | + /** |
|
570 | + * Make the Express checkout request. |
|
571 | + * |
|
572 | + * @param array $request_params |
|
573 | + * @param string $request_text |
|
574 | + * @param EEI_Payment $payment |
|
575 | + * @return mixed |
|
576 | + */ |
|
577 | + public function _ppExpress_request($request_params, $request_text, $payment) |
|
578 | + { |
|
579 | + $request_dtls = array( |
|
580 | + 'VERSION' => '204.0', |
|
581 | + 'USER' => $this->_api_username, |
|
582 | + 'PWD' => $this->_api_password, |
|
583 | + 'SIGNATURE' => $this->_api_signature, |
|
584 | + // EE will blow up if you change this |
|
585 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
586 | + ); |
|
587 | + $dtls = array_merge($request_dtls, $request_params); |
|
588 | + $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
589 | + // Request Customer Details. |
|
590 | + $request_response = wp_remote_post( |
|
591 | + $this->_base_gateway_url, |
|
592 | + array( |
|
593 | + 'method' => 'POST', |
|
594 | + 'timeout' => 45, |
|
595 | + 'httpversion' => '1.1', |
|
596 | + 'cookies' => array(), |
|
597 | + 'headers' => array(), |
|
598 | + 'body' => http_build_query($dtls, '', '&'), |
|
599 | + ) |
|
600 | + ); |
|
601 | + // Log the response. |
|
602 | + $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
603 | + return $request_response; |
|
604 | + } |
|
605 | + |
|
606 | + |
|
607 | + |
|
608 | + /** |
|
609 | + * Check the response status. |
|
610 | + * |
|
611 | + * @param mixed $request_response |
|
612 | + * @return array |
|
613 | + */ |
|
614 | + public function _ppExpress_check_response($request_response) |
|
615 | + { |
|
616 | + if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
617 | + // If we got here then there was an error in this request. |
|
618 | + return array('status' => false, 'args' => $request_response); |
|
619 | + } |
|
620 | + $response_args = array(); |
|
621 | + parse_str(urldecode($request_response['body']), $response_args); |
|
622 | + if (! isset($response_args['ACK'])) { |
|
623 | + return array('status' => false, 'args' => $request_response); |
|
624 | + } |
|
625 | + if ( |
|
626 | + ( |
|
627 | + isset($response_args['PAYERID']) |
|
628 | + || isset($response_args['TOKEN']) |
|
629 | + || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
630 | + || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
631 | + ) |
|
632 | + && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
633 | + ) { |
|
634 | + // Response status OK, return response parameters for further processing. |
|
635 | + return array('status' => true, 'args' => $response_args); |
|
636 | + } |
|
637 | + $errors = $this->_get_errors($response_args); |
|
638 | + return array('status' => false, 'args' => $errors); |
|
639 | + } |
|
640 | + |
|
641 | + |
|
642 | + |
|
643 | + /** |
|
644 | + * Log a "Cleared" request. |
|
645 | + * |
|
646 | + * @param array $request |
|
647 | + * @param EEI_Payment $payment |
|
648 | + * @param string $info |
|
649 | + * @return void |
|
650 | + */ |
|
651 | + private function _log_clean_request($request, $payment, $info) |
|
652 | + { |
|
653 | + $cleaned_request_data = $request; |
|
654 | + unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
655 | + $this->log(array($info => $cleaned_request_data), $payment); |
|
656 | + } |
|
657 | + |
|
658 | + |
|
659 | + |
|
660 | + /** |
|
661 | + * Get error from the response data. |
|
662 | + * |
|
663 | + * @param array $data_array |
|
664 | + * @return array |
|
665 | + */ |
|
666 | + private function _get_errors($data_array) |
|
667 | + { |
|
668 | + $errors = array(); |
|
669 | + $n = 0; |
|
670 | + while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
671 | + $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
672 | + ? $data_array[ "L_ERRORCODE{$n}" ] |
|
673 | + : ''; |
|
674 | + $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
675 | + ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
676 | + : ''; |
|
677 | + $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
678 | + ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
679 | + : ''; |
|
680 | + $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
681 | + ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
682 | + : ''; |
|
683 | + if ($n === 0) { |
|
684 | + $errors = array( |
|
685 | + 'L_ERRORCODE' => $l_error_code, |
|
686 | + 'L_SHORTMESSAGE' => $l_short_message, |
|
687 | + 'L_LONGMESSAGE' => $l_long_message, |
|
688 | + 'L_SEVERITYCODE' => $l_severity_code, |
|
689 | + ); |
|
690 | + } else { |
|
691 | + $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
692 | + $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
693 | + $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
694 | + $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
695 | + } |
|
696 | + $n++; |
|
697 | + } |
|
698 | + return $errors; |
|
699 | + } |
|
700 | 700 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
15 | -if (! function_exists('mb_strcut')) { |
|
15 | +if ( ! function_exists('mb_strcut')) { |
|
16 | 16 | /** |
17 | 17 | * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
18 | 18 | * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | $notify_url = null, |
152 | 152 | $cancel_url = null |
153 | 153 | ) { |
154 | - if (! $payment instanceof EEI_Payment) { |
|
154 | + if ( ! $payment instanceof EEI_Payment) { |
|
155 | 155 | $payment->set_gateway_response( |
156 | 156 | esc_html__( |
157 | 157 | 'Error. No associated payment was found.', |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | return $payment; |
163 | 163 | } |
164 | 164 | $transaction = $payment->transaction(); |
165 | - if (! $transaction instanceof EEI_Transaction) { |
|
165 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
166 | 166 | $payment->set_gateway_response( |
167 | 167 | esc_html__( |
168 | 168 | 'Could not process this payment because it has no associated transaction.', |
@@ -209,13 +209,13 @@ discard block |
||
209 | 209 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
210 | 210 | $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
211 | 211 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
212 | - } elseif (! $this->_request_shipping_addr) { |
|
212 | + } elseif ( ! $this->_request_shipping_addr) { |
|
213 | 213 | // Do not request shipping details on the PP Checkout page. |
214 | 214 | $token_request_dtls['NOSHIPPING'] = '1'; |
215 | 215 | $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
216 | 216 | } |
217 | 217 | // Used a business/personal logo on the PayPal page. |
218 | - if (! empty($this->_image_url)) { |
|
218 | + if ( ! empty($this->_image_url)) { |
|
219 | 219 | $token_request_dtls['LOGOIMG'] = $this->_image_url; |
220 | 220 | } |
221 | 221 | $token_request_dtls = apply_filters( |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | ); |
241 | 241 | } else { |
242 | 242 | if (isset($response_args['L_ERRORCODE'])) { |
243 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
243 | + $payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']); |
|
244 | 244 | } else { |
245 | 245 | $payment->set_gateway_response( |
246 | 246 | esc_html__( |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | if ($payment instanceof EEI_Payment) { |
272 | 272 | $this->log(array('Return from Authorization' => $update_info), $payment); |
273 | 273 | $transaction = $payment->transaction(); |
274 | - if (! $transaction instanceof EEI_Transaction) { |
|
274 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
275 | 275 | $payment->set_gateway_response( |
276 | 276 | esc_html__( |
277 | 277 | 'Could not process this payment because it has no associated transaction.', |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | $primary_registrant = $transaction->primary_registration(); |
285 | 285 | $payment_details = $payment->details(); |
286 | 286 | // Check if we still have the token. |
287 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
287 | + if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
288 | 288 | $payment->set_status($this->_pay_model->failed_status()); |
289 | 289 | return $payment; |
290 | 290 | } |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | strpos($arg_key, 'PAYMENTREQUEST_') !== false |
420 | 420 | && strpos($arg_key, 'NOTIFYURL') === false |
421 | 421 | ) { |
422 | - $itemized_list[ $arg_key ] = $arg_val; |
|
422 | + $itemized_list[$arg_key] = $arg_val; |
|
423 | 423 | } |
424 | 424 | } |
425 | 425 | // If we got only a few Items then something is not right. |
@@ -472,28 +472,28 @@ discard block |
||
472 | 472 | $line_item_quantity = 1; |
473 | 473 | } |
474 | 474 | // Item Name. |
475 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
475 | + $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut( |
|
476 | 476 | $gateway_formatter->formatLineItemName($line_item, $payment), |
477 | 477 | 0, |
478 | 478 | 127 |
479 | 479 | ); |
480 | 480 | // Item description. |
481 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
481 | + $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = mb_strcut( |
|
482 | 482 | $gateway_formatter->formatLineItemDesc($line_item, $payment), |
483 | 483 | 0, |
484 | 484 | 127 |
485 | 485 | ); |
486 | 486 | // Cost of individual item. |
487 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
487 | + $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $gateway_formatter->formatCurrency( |
|
488 | 488 | $unit_price, |
489 | 489 | $this->decimal_precision |
490 | 490 | ); |
491 | 491 | // Item Number. |
492 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
492 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
|
493 | 493 | // Item quantity. |
494 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
494 | + $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = $line_item_quantity; |
|
495 | 495 | // Digital item is sold. |
496 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
496 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
497 | 497 | $itemized_sum += $line_item->total(); |
498 | 498 | ++$item_num; |
499 | 499 | } |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | // add the difference as an extra line item. |
512 | 512 | if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
513 | 513 | // Item Name. |
514 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
514 | + $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut( |
|
515 | 515 | esc_html__( |
516 | 516 | 'Other (promotion/surcharge/cancellation)', |
517 | 517 | 'event_espresso' |
@@ -520,17 +520,17 @@ discard block |
||
520 | 520 | 127 |
521 | 521 | ); |
522 | 522 | // Item description. |
523 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
523 | + $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = ''; |
|
524 | 524 | // Cost of individual item. |
525 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
525 | + $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $gateway_formatter->formatCurrency( |
|
526 | 526 | $itemized_sum_diff_from_txn_total |
527 | 527 | ); |
528 | 528 | // Item Number. |
529 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
529 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
|
530 | 530 | // Item quantity. |
531 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
531 | + $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1; |
|
532 | 532 | // Digital item is sold. |
533 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
533 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
534 | 534 | $item_num++; |
535 | 535 | } |
536 | 536 | } else { |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | 'BUTTONSOURCE' => 'EventEspresso_SP', |
586 | 586 | ); |
587 | 587 | $dtls = array_merge($request_dtls, $request_params); |
588 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
588 | + $this->_log_clean_request($dtls, $payment, $request_text.' Request'); |
|
589 | 589 | // Request Customer Details. |
590 | 590 | $request_response = wp_remote_post( |
591 | 591 | $this->_base_gateway_url, |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | ) |
600 | 600 | ); |
601 | 601 | // Log the response. |
602 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
602 | + $this->log(array($request_text.' Response' => $request_response), $payment); |
|
603 | 603 | return $request_response; |
604 | 604 | } |
605 | 605 | |
@@ -619,7 +619,7 @@ discard block |
||
619 | 619 | } |
620 | 620 | $response_args = array(); |
621 | 621 | parse_str(urldecode($request_response['body']), $response_args); |
622 | - if (! isset($response_args['ACK'])) { |
|
622 | + if ( ! isset($response_args['ACK'])) { |
|
623 | 623 | return array('status' => false, 'args' => $request_response); |
624 | 624 | } |
625 | 625 | if ( |
@@ -667,18 +667,18 @@ discard block |
||
667 | 667 | { |
668 | 668 | $errors = array(); |
669 | 669 | $n = 0; |
670 | - while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
671 | - $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
672 | - ? $data_array[ "L_ERRORCODE{$n}" ] |
|
670 | + while (isset($data_array["L_ERRORCODE{$n}"])) { |
|
671 | + $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
|
672 | + ? $data_array["L_ERRORCODE{$n}"] |
|
673 | 673 | : ''; |
674 | - $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
675 | - ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
674 | + $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"]) |
|
675 | + ? $data_array["L_SEVERITYCODE{$n}"] |
|
676 | 676 | : ''; |
677 | - $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
678 | - ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
677 | + $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"]) |
|
678 | + ? $data_array["L_SHORTMESSAGE{$n}"] |
|
679 | 679 | : ''; |
680 | - $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
681 | - ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
680 | + $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"]) |
|
681 | + ? $data_array["L_LONGMESSAGE{$n}"] |
|
682 | 682 | : ''; |
683 | 683 | if ($n === 0) { |
684 | 684 | $errors = array( |
@@ -688,10 +688,10 @@ discard block |
||
688 | 688 | 'L_SEVERITYCODE' => $l_severity_code, |
689 | 689 | ); |
690 | 690 | } else { |
691 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
692 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
693 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
694 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
691 | + $errors['L_ERRORCODE'] .= ', '.$l_error_code; |
|
692 | + $errors['L_SHORTMESSAGE'] .= ', '.$l_short_message; |
|
693 | + $errors['L_LONGMESSAGE'] .= ', '.$l_long_message; |
|
694 | + $errors['L_SEVERITYCODE'] .= ', '.$l_severity_code; |
|
695 | 695 | } |
696 | 696 | $n++; |
697 | 697 | } |
@@ -16,1162 +16,1162 @@ |
||
16 | 16 | class Payments_Admin_Page extends EE_Admin_Page |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Variables used for when we're re-sorting the logs results, in case |
|
21 | - * we needed to do two queries and we need to resort |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - private $_sort_logs_again_direction; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * @Constructor |
|
30 | - * @access public |
|
31 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
32 | - * @throws EE_Error |
|
33 | - * @throws InvalidArgumentException |
|
34 | - * @throws InvalidDataTypeException |
|
35 | - * @throws InvalidInterfaceException |
|
36 | - * @throws ReflectionException |
|
37 | - */ |
|
38 | - public function __construct($routing = true) |
|
39 | - { |
|
40 | - parent::__construct($routing); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - protected function _init_page_props() |
|
45 | - { |
|
46 | - $this->page_slug = EE_PAYMENTS_PG_SLUG; |
|
47 | - $this->page_label = __('Payment Methods', 'event_espresso'); |
|
48 | - $this->_admin_base_url = EE_PAYMENTS_ADMIN_URL; |
|
49 | - $this->_admin_base_path = EE_PAYMENTS_ADMIN; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - protected function _ajax_hooks() |
|
54 | - { |
|
55 | - // todo: all hooks for ajax goes here. |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - protected function _define_page_props() |
|
60 | - { |
|
61 | - $this->_admin_page_title = $this->page_label; |
|
62 | - $this->_labels = array( |
|
63 | - 'publishbox' => __('Update Settings', 'event_espresso'), |
|
64 | - ); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - protected function _set_page_routes() |
|
69 | - { |
|
70 | - /** |
|
71 | - * note that with payment method capabilities, although we've implemented |
|
72 | - * capability mapping which will be used for accessing payment methods owned by |
|
73 | - * other users. This is not fully implemented yet in the payment method ui. |
|
74 | - * Currently only the "plural" caps are in active use. |
|
75 | - * When cap mapping is implemented, some routes will need to use the singular form of |
|
76 | - * capability method and also include the $id of the payment method for the route. |
|
77 | - **/ |
|
78 | - $this->_page_routes = array( |
|
79 | - 'default' => array( |
|
80 | - 'func' => '_payment_methods_list', |
|
81 | - 'capability' => 'ee_edit_payment_methods', |
|
82 | - ), |
|
83 | - 'payment_settings' => array( |
|
84 | - 'func' => '_payment_settings', |
|
85 | - 'capability' => 'ee_manage_gateways', |
|
86 | - ), |
|
87 | - 'activate_payment_method' => array( |
|
88 | - 'func' => '_activate_payment_method', |
|
89 | - 'noheader' => true, |
|
90 | - 'capability' => 'ee_edit_payment_methods', |
|
91 | - ), |
|
92 | - 'deactivate_payment_method' => array( |
|
93 | - 'func' => '_deactivate_payment_method', |
|
94 | - 'noheader' => true, |
|
95 | - 'capability' => 'ee_delete_payment_methods', |
|
96 | - ), |
|
97 | - 'update_payment_method' => array( |
|
98 | - 'func' => '_update_payment_method', |
|
99 | - 'noheader' => true, |
|
100 | - 'headers_sent_route' => 'default', |
|
101 | - 'capability' => 'ee_edit_payment_methods', |
|
102 | - ), |
|
103 | - 'update_payment_settings' => array( |
|
104 | - 'func' => '_update_payment_settings', |
|
105 | - 'noheader' => true, |
|
106 | - 'capability' => 'ee_manage_gateways', |
|
107 | - ), |
|
108 | - 'payment_log' => array( |
|
109 | - 'func' => '_payment_log_overview_list_table', |
|
110 | - 'capability' => 'ee_read_payment_methods', |
|
111 | - ), |
|
112 | - 'payment_log_details' => array( |
|
113 | - 'func' => '_payment_log_details', |
|
114 | - 'capability' => 'ee_read_payment_methods', |
|
115 | - ), |
|
116 | - ); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - protected function _set_page_config() |
|
121 | - { |
|
122 | - $payment_method_list_config = array( |
|
123 | - 'nav' => array( |
|
124 | - 'label' => __('Payment Methods', 'event_espresso'), |
|
125 | - 'order' => 10, |
|
126 | - ), |
|
127 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
128 | - 'help_tabs' => array_merge( |
|
129 | - array( |
|
130 | - 'payment_methods_overview_help_tab' => array( |
|
131 | - 'title' => __('Payment Methods Overview', 'event_espresso'), |
|
132 | - 'filename' => 'payment_methods_overview', |
|
133 | - ), |
|
134 | - ), |
|
135 | - $this->_add_payment_method_help_tabs() |
|
136 | - ), |
|
137 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
138 | - // 'help_tour' => array('Payment_Methods_Selection_Help_Tour'), |
|
139 | - 'require_nonce' => false, |
|
140 | - ); |
|
141 | - $this->_page_config = array( |
|
142 | - 'default' => $payment_method_list_config, |
|
143 | - 'payment_settings' => array( |
|
144 | - 'nav' => array( |
|
145 | - 'label' => __('Settings', 'event_espresso'), |
|
146 | - 'order' => 20, |
|
147 | - ), |
|
148 | - 'help_tabs' => array( |
|
149 | - 'payment_methods_settings_help_tab' => array( |
|
150 | - 'title' => __('Payment Method Settings', 'event_espresso'), |
|
151 | - 'filename' => 'payment_methods_settings', |
|
152 | - ), |
|
153 | - ), |
|
154 | - // 'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ), |
|
155 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
156 | - 'require_nonce' => false, |
|
157 | - ), |
|
158 | - 'payment_log' => array( |
|
159 | - 'nav' => array( |
|
160 | - 'label' => __("Logs", 'event_espresso'), |
|
161 | - 'order' => 30, |
|
162 | - ), |
|
163 | - 'list_table' => 'Payment_Log_Admin_List_Table', |
|
164 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
165 | - 'require_nonce' => false, |
|
166 | - ), |
|
167 | - ); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @return array |
|
173 | - * @throws DomainException |
|
174 | - * @throws EE_Error |
|
175 | - * @throws InvalidArgumentException |
|
176 | - * @throws InvalidDataTypeException |
|
177 | - * @throws InvalidInterfaceException |
|
178 | - * @throws ReflectionException |
|
179 | - */ |
|
180 | - protected function _add_payment_method_help_tabs() |
|
181 | - { |
|
182 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
183 | - $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types(); |
|
184 | - $all_pmt_help_tabs_config = array(); |
|
185 | - foreach ($payment_method_types as $payment_method_type) { |
|
186 | - if ( |
|
187 | - ! EE_Registry::instance()->CAP->current_user_can( |
|
188 | - $payment_method_type->cap_name(), |
|
189 | - 'specific_payment_method_type_access' |
|
190 | - ) |
|
191 | - ) { |
|
192 | - continue; |
|
193 | - } |
|
194 | - foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) { |
|
195 | - $template_args = isset($config['template_args']) ? $config['template_args'] : array(); |
|
196 | - $template_args['admin_page_obj'] = $this; |
|
197 | - $all_pmt_help_tabs_config[ $help_tab_name ] = array( |
|
198 | - 'title' => $config['title'], |
|
199 | - 'content' => EEH_Template::display_template( |
|
200 | - $payment_method_type->file_folder() . 'help_tabs/' . $config['filename'] . '.help_tab.php', |
|
201 | - $template_args, |
|
202 | - true |
|
203 | - ), |
|
204 | - ); |
|
205 | - } |
|
206 | - } |
|
207 | - return $all_pmt_help_tabs_config; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - // none of the below group are currently used for Gateway Settings |
|
212 | - protected function _add_screen_options() |
|
213 | - { |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - protected function _add_feature_pointers() |
|
218 | - { |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - public function admin_init() |
|
223 | - { |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - public function admin_notices() |
|
228 | - { |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - public function admin_footer_scripts() |
|
233 | - { |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - public function load_scripts_styles() |
|
238 | - { |
|
239 | - // styles |
|
240 | - wp_enqueue_style('espresso-ui-theme'); |
|
241 | - wp_register_style( |
|
242 | - 'espresso_payments', |
|
243 | - EE_PAYMENTS_ASSETS_URL . 'ee-payments.css', |
|
244 | - [], |
|
245 | - EVENT_ESPRESSO_VERSION |
|
246 | - ); |
|
247 | - // scripts |
|
248 | - wp_enqueue_script('ee_admin_js'); |
|
249 | - wp_enqueue_script('ee-text-links'); |
|
250 | - wp_enqueue_script( |
|
251 | - 'espresso_payments', |
|
252 | - EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js', |
|
253 | - ['ee-datepicker'], |
|
254 | - EVENT_ESPRESSO_VERSION, |
|
255 | - true |
|
256 | - ); |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - public function load_scripts_styles_default() |
|
261 | - { |
|
262 | - wp_enqueue_style('espresso_payments'); |
|
263 | - wp_enqueue_style('ee-text-links'); |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - public function load_scripts_styles_payment_log_details() |
|
268 | - { |
|
269 | - wp_enqueue_style('espresso_payments'); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - protected function _payment_methods_list() |
|
274 | - { |
|
275 | - /** |
|
276 | - * first let's ensure payment methods have been setup. We do this here because when people activate a |
|
277 | - * payment method for the first time (as an addon), it may not setup its capabilities or get registered |
|
278 | - * correctly due to the loading process. However, people MUST setup the details for the payment method so its |
|
279 | - * safe to do a recheck here. |
|
280 | - */ |
|
281 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
282 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
283 | - // setup tabs, one for each payment method type |
|
284 | - $tabs = array(); |
|
285 | - $payment_methods = array(); |
|
286 | - foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) { |
|
287 | - // we don't want to show admin-only PMTs for now |
|
288 | - if ($pmt_obj instanceof EE_PMT_Admin_Only) { |
|
289 | - continue; |
|
290 | - } |
|
291 | - // check access |
|
292 | - if ( |
|
293 | - ! EE_Registry::instance()->CAP->current_user_can( |
|
294 | - $pmt_obj->cap_name(), |
|
295 | - 'specific_payment_method_type_access' |
|
296 | - ) |
|
297 | - ) { |
|
298 | - continue; |
|
299 | - } |
|
300 | - // check for any active pms of that type |
|
301 | - $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name()); |
|
302 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
303 | - $payment_method = EE_Payment_Method::new_instance( |
|
304 | - array( |
|
305 | - 'PMD_slug' => sanitize_key($pmt_obj->system_name()), |
|
306 | - 'PMD_type' => $pmt_obj->system_name(), |
|
307 | - 'PMD_name' => $pmt_obj->pretty_name(), |
|
308 | - 'PMD_admin_name' => $pmt_obj->pretty_name(), |
|
309 | - ) |
|
310 | - ); |
|
311 | - } |
|
312 | - $payment_methods[ $payment_method->slug() ] = $payment_method; |
|
313 | - } |
|
314 | - $payment_methods = apply_filters( |
|
315 | - 'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', |
|
316 | - $payment_methods |
|
317 | - ); |
|
318 | - foreach ($payment_methods as $payment_method) { |
|
319 | - if ($payment_method instanceof EE_Payment_Method) { |
|
320 | - add_meta_box( |
|
321 | - // html id |
|
322 | - 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
323 | - // title |
|
324 | - sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()), |
|
325 | - // callback |
|
326 | - array($this, 'payment_method_settings_meta_box'), |
|
327 | - // post type |
|
328 | - null, |
|
329 | - // context |
|
330 | - 'normal', |
|
331 | - // priority |
|
332 | - 'default', |
|
333 | - // callback args |
|
334 | - array('payment_method' => $payment_method) |
|
335 | - ); |
|
336 | - // setup for tabbed content |
|
337 | - $tabs[ $payment_method->slug() ] = array( |
|
338 | - 'label' => $payment_method->admin_name(), |
|
339 | - 'class' => $payment_method->active() ? 'gateway-active' : '', |
|
340 | - 'href' => 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
341 | - 'title' => __('Modify this Payment Method', 'event_espresso'), |
|
342 | - 'slug' => $payment_method->slug(), |
|
343 | - ); |
|
344 | - } |
|
345 | - } |
|
346 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
347 | - $tabs, |
|
348 | - 'payment_method_links', |
|
349 | - '|', |
|
350 | - $this->_get_active_payment_method_slug() |
|
351 | - ); |
|
352 | - $this->display_admin_page_with_sidebar(); |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * _get_active_payment_method_slug |
|
358 | - * |
|
359 | - * @return string |
|
360 | - */ |
|
361 | - protected function _get_active_payment_method_slug() |
|
362 | - { |
|
363 | - $payment_method_slug = false; |
|
364 | - // decide which payment method tab to open first, as dictated by the request's 'payment_method' |
|
365 | - if (isset($this->_req_data['payment_method'])) { |
|
366 | - // if they provided the current payment method, use it |
|
367 | - $payment_method_slug = sanitize_key($this->_req_data['payment_method']); |
|
368 | - } |
|
369 | - $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug))); |
|
370 | - // if that didn't work or wasn't provided, find another way to select the current pm |
|
371 | - if (! $this->_verify_payment_method($payment_method)) { |
|
372 | - // like, looking for an active one |
|
373 | - $payment_method = EEM_Payment_Method::instance()->get_one_active('CART'); |
|
374 | - // test that one as well |
|
375 | - if ($this->_verify_payment_method($payment_method)) { |
|
376 | - $payment_method_slug = $payment_method->slug(); |
|
377 | - } else { |
|
378 | - $payment_method_slug = 'paypal_standard'; |
|
379 | - } |
|
380 | - } |
|
381 | - return $payment_method_slug; |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * payment_method_settings_meta_box |
|
387 | - * returns TRUE if the passed payment method is properly constructed and the logged in user has the correct |
|
388 | - * capabilities to access it |
|
389 | - * |
|
390 | - * @param EE_Payment_Method $payment_method |
|
391 | - * @return boolean |
|
392 | - */ |
|
393 | - protected function _verify_payment_method($payment_method) |
|
394 | - { |
|
395 | - if ( |
|
396 | - $payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base |
|
397 | - && EE_Registry::instance()->CAP->current_user_can( |
|
398 | - $payment_method->type_obj()->cap_name(), |
|
399 | - 'specific_payment_method_type_access' |
|
400 | - ) |
|
401 | - ) { |
|
402 | - return true; |
|
403 | - } |
|
404 | - return false; |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * payment_method_settings_meta_box |
|
410 | - * |
|
411 | - * @param NULL $post_obj_which_is_null is an object containing the current post (as a $post object) |
|
412 | - * @param array $metabox is an array with metabox id, title, callback, and args elements. the value |
|
413 | - * at 'args' has key 'payment_method', as set within _payment_methods_list |
|
414 | - * @return string |
|
415 | - * @throws EE_Error |
|
416 | - */ |
|
417 | - public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox) |
|
418 | - { |
|
419 | - $payment_method = isset($metabox['args'], $metabox['args']['payment_method']) |
|
420 | - ? $metabox['args']['payment_method'] : null; |
|
421 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
422 | - throw new EE_Error( |
|
423 | - sprintf( |
|
424 | - __( |
|
425 | - 'Payment method metabox setup incorrectly. No Payment method object was supplied', |
|
426 | - 'event_espresso' |
|
427 | - ) |
|
428 | - ) |
|
429 | - ); |
|
430 | - } |
|
431 | - $payment_method_scopes = $payment_method->active(); |
|
432 | - // if the payment method really exists show its form, otherwise the activation template |
|
433 | - if ($payment_method->ID() && ! empty($payment_method_scopes)) { |
|
434 | - $form = $this->_generate_payment_method_settings_form($payment_method); |
|
435 | - if ($form->form_data_present_in($this->_req_data)) { |
|
436 | - $form->receive_form_submission($this->_req_data); |
|
437 | - } |
|
438 | - echo $form->form_open() . $form->get_html_and_js() . $form->form_close(); |
|
439 | - } else { |
|
440 | - echo $this->_activate_payment_method_button($payment_method)->get_html_and_js(); |
|
441 | - } |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * Gets the form for all the settings related to this payment method type |
|
447 | - * |
|
448 | - * @access protected |
|
449 | - * @param EE_Payment_Method $payment_method |
|
450 | - * @return EE_Form_Section_Proper |
|
451 | - */ |
|
452 | - protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method) |
|
453 | - { |
|
454 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
455 | - return new EE_Form_Section_Proper(); |
|
456 | - } |
|
457 | - return new EE_Form_Section_Proper( |
|
458 | - array( |
|
459 | - 'name' => $payment_method->slug() . '_settings_form', |
|
460 | - 'html_id' => $payment_method->slug() . '_settings_form', |
|
461 | - 'action' => EE_Admin_Page::add_query_args_and_nonce( |
|
462 | - array( |
|
463 | - 'action' => 'update_payment_method', |
|
464 | - 'payment_method' => $payment_method->slug(), |
|
465 | - ), |
|
466 | - EE_PAYMENTS_ADMIN_URL |
|
467 | - ), |
|
468 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
469 | - 'subsections' => apply_filters( |
|
470 | - 'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections', |
|
471 | - array( |
|
472 | - 'pci_dss_compliance' => $this->_pci_dss_compliance($payment_method), |
|
473 | - 'currency_support' => $this->_currency_support($payment_method), |
|
474 | - 'payment_method_settings' => $this->_payment_method_settings($payment_method), |
|
475 | - 'update' => $this->_update_payment_method_button($payment_method), |
|
476 | - 'deactivate' => $this->_deactivate_payment_method_button($payment_method), |
|
477 | - 'fine_print' => $this->_fine_print(), |
|
478 | - ), |
|
479 | - $payment_method |
|
480 | - ), |
|
481 | - ) |
|
482 | - ); |
|
483 | - } |
|
484 | - |
|
485 | - |
|
486 | - /** |
|
487 | - * _pci_dss_compliance |
|
488 | - * |
|
489 | - * @access protected |
|
490 | - * @param EE_Payment_Method $payment_method |
|
491 | - * @return EE_Form_Section_Proper |
|
492 | - */ |
|
493 | - protected function _pci_dss_compliance(EE_Payment_Method $payment_method) |
|
494 | - { |
|
495 | - if ($payment_method->type_obj()->requires_https()) { |
|
496 | - return new EE_Form_Section_HTML( |
|
497 | - EEH_HTML::table( |
|
498 | - EEH_HTML::tr( |
|
499 | - EEH_HTML::th( |
|
500 | - EEH_HTML::label( |
|
501 | - EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
|
502 | - ) |
|
503 | - ) . |
|
504 | - EEH_HTML::td( |
|
505 | - EEH_HTML::strong( |
|
506 | - __( |
|
507 | - 'You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.', |
|
508 | - 'event_espresso' |
|
509 | - ) |
|
510 | - ) |
|
511 | - . |
|
512 | - EEH_HTML::br() |
|
513 | - . |
|
514 | - __('Learn more about ', 'event_espresso') |
|
515 | - . EEH_HTML::link( |
|
516 | - 'https://www.pcisecuritystandards.org/merchants/index.php', |
|
517 | - __('PCI DSS compliance', 'event_espresso') |
|
518 | - ) |
|
519 | - ) |
|
520 | - ) |
|
521 | - ) |
|
522 | - ); |
|
523 | - } else { |
|
524 | - return new EE_Form_Section_HTML(''); |
|
525 | - } |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * _currency_support |
|
531 | - * |
|
532 | - * @access protected |
|
533 | - * @param EE_Payment_Method $payment_method |
|
534 | - * @return EE_Form_Section_Proper |
|
535 | - */ |
|
536 | - protected function _currency_support(EE_Payment_Method $payment_method) |
|
537 | - { |
|
538 | - if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) { |
|
539 | - return new EE_Form_Section_HTML( |
|
540 | - EEH_HTML::table( |
|
541 | - EEH_HTML::tr( |
|
542 | - EEH_HTML::th( |
|
543 | - EEH_HTML::label( |
|
544 | - EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
|
545 | - ) |
|
546 | - ) . |
|
547 | - EEH_HTML::td( |
|
548 | - EEH_HTML::strong( |
|
549 | - sprintf( |
|
550 | - __( |
|
551 | - 'This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.', |
|
552 | - 'event_espresso' |
|
553 | - ), |
|
554 | - EE_Config::instance()->currency->code |
|
555 | - ) |
|
556 | - ) |
|
557 | - ) |
|
558 | - ) |
|
559 | - ) |
|
560 | - ); |
|
561 | - } else { |
|
562 | - return new EE_Form_Section_HTML(''); |
|
563 | - } |
|
564 | - } |
|
565 | - |
|
566 | - |
|
567 | - /** |
|
568 | - * _update_payment_method_button |
|
569 | - * |
|
570 | - * @access protected |
|
571 | - * @param EE_Payment_Method $payment_method |
|
572 | - * @return EE_Payment_Method_Form |
|
573 | - */ |
|
574 | - protected function _payment_method_settings(EE_Payment_Method $payment_method) |
|
575 | - { |
|
576 | - // modify the form so we only have/show fields that will be implemented for this version |
|
577 | - return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name()); |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - /** |
|
582 | - * Simplifies the form to merely reproduce 4.1's gateway settings functionality |
|
583 | - * |
|
584 | - * @param EE_Form_Section_Proper $form_section |
|
585 | - * @param string $payment_method_name |
|
586 | - * @return EE_Payment_Method_Form |
|
587 | - * @throws EE_Error |
|
588 | - */ |
|
589 | - protected function _simplify_form($form_section, $payment_method_name = '') |
|
590 | - { |
|
591 | - if ($form_section instanceof EE_Payment_Method_Form) { |
|
592 | - $form_section->exclude( |
|
593 | - array( |
|
594 | - 'PMD_type', // dont want them changing the type |
|
595 | - 'PMD_slug', // or the slug (probably never) |
|
596 | - 'PMD_wp_user', // or the user's ID |
|
597 | - 'Currency' // or the currency, until the rest of EE supports simultaneous currencies |
|
598 | - ) |
|
599 | - ); |
|
600 | - return $form_section; |
|
601 | - } else { |
|
602 | - throw new EE_Error( |
|
603 | - sprintf( |
|
604 | - __( |
|
605 | - 'The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.', |
|
606 | - 'event_espresso' |
|
607 | - ), |
|
608 | - $payment_method_name |
|
609 | - ) |
|
610 | - ); |
|
611 | - } |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - /** |
|
616 | - * _update_payment_method_button |
|
617 | - * |
|
618 | - * @access protected |
|
619 | - * @param EE_Payment_Method $payment_method |
|
620 | - * @return EE_Form_Section_HTML |
|
621 | - */ |
|
622 | - protected function _update_payment_method_button(EE_Payment_Method $payment_method) |
|
623 | - { |
|
624 | - $update_button = new EE_Submit_Input( |
|
625 | - array( |
|
626 | - 'name' => 'submit', |
|
627 | - 'html_id' => 'save_' . $payment_method->slug() . '_settings', |
|
628 | - 'default' => sprintf( |
|
629 | - __('Update %s Payment Settings', 'event_espresso'), |
|
630 | - $payment_method->admin_name() |
|
631 | - ), |
|
632 | - 'html_label' => EEH_HTML::nbsp(), |
|
633 | - ) |
|
634 | - ); |
|
635 | - return new EE_Form_Section_HTML( |
|
636 | - EEH_HTML::table( |
|
637 | - EEH_HTML::no_row(EEH_HTML::br(2)) . |
|
638 | - EEH_HTML::tr( |
|
639 | - EEH_HTML::th(__('Update Settings', 'event_espresso')) . |
|
640 | - EEH_HTML::td( |
|
641 | - $update_button->get_html_for_input() |
|
642 | - ) |
|
643 | - ) |
|
644 | - ) |
|
645 | - ); |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * _deactivate_payment_method_button |
|
651 | - * |
|
652 | - * @access protected |
|
653 | - * @param EE_Payment_Method $payment_method |
|
654 | - * @return EE_Form_Section_Proper |
|
655 | - */ |
|
656 | - protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method) |
|
657 | - { |
|
658 | - $link_text_and_title = sprintf( |
|
659 | - __('Deactivate %1$s Payments?', 'event_espresso'), |
|
660 | - $payment_method->admin_name() |
|
661 | - ); |
|
662 | - return new EE_Form_Section_HTML( |
|
663 | - EEH_HTML::table( |
|
664 | - EEH_HTML::tr( |
|
665 | - EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) . |
|
666 | - EEH_HTML::td( |
|
667 | - EEH_HTML::link( |
|
668 | - EE_Admin_Page::add_query_args_and_nonce( |
|
669 | - array( |
|
670 | - 'action' => 'deactivate_payment_method', |
|
671 | - 'payment_method' => $payment_method->slug(), |
|
672 | - ), |
|
673 | - EE_PAYMENTS_ADMIN_URL |
|
674 | - ), |
|
675 | - $link_text_and_title, |
|
676 | - $link_text_and_title, |
|
677 | - 'deactivate_' . $payment_method->slug(), |
|
678 | - 'espresso-button button-secondary' |
|
679 | - ) |
|
680 | - ) |
|
681 | - ) |
|
682 | - ) |
|
683 | - ); |
|
684 | - } |
|
685 | - |
|
686 | - |
|
687 | - /** |
|
688 | - * _activate_payment_method_button |
|
689 | - * |
|
690 | - * @access protected |
|
691 | - * @param EE_Payment_Method $payment_method |
|
692 | - * @return EE_Form_Section_Proper |
|
693 | - */ |
|
694 | - protected function _activate_payment_method_button(EE_Payment_Method $payment_method) |
|
695 | - { |
|
696 | - $link_text_and_title = sprintf( |
|
697 | - __('Activate %1$s Payment Method?', 'event_espresso'), |
|
698 | - $payment_method->admin_name() |
|
699 | - ); |
|
700 | - return new EE_Form_Section_Proper( |
|
701 | - array( |
|
702 | - 'name' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
703 | - 'html_id' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
704 | - 'action' => '#', |
|
705 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
706 | - 'subsections' => apply_filters( |
|
707 | - 'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections', |
|
708 | - array( |
|
709 | - new EE_Form_Section_HTML( |
|
710 | - EEH_HTML::table( |
|
711 | - EEH_HTML::tr( |
|
712 | - EEH_HTML::td( |
|
713 | - $payment_method->type_obj()->introductory_html(), |
|
714 | - '', |
|
715 | - '', |
|
716 | - '', |
|
717 | - 'colspan="2"' |
|
718 | - ) |
|
719 | - ) . |
|
720 | - EEH_HTML::tr( |
|
721 | - EEH_HTML::th( |
|
722 | - EEH_HTML::label(__('Click to Activate ', 'event_espresso')) |
|
723 | - ) . |
|
724 | - EEH_HTML::td( |
|
725 | - EEH_HTML::link( |
|
726 | - EE_Admin_Page::add_query_args_and_nonce( |
|
727 | - array( |
|
728 | - 'action' => 'activate_payment_method', |
|
729 | - 'payment_method_type' => $payment_method->type(), |
|
730 | - ), |
|
731 | - EE_PAYMENTS_ADMIN_URL |
|
732 | - ), |
|
733 | - $link_text_and_title, |
|
734 | - $link_text_and_title, |
|
735 | - 'activate_' . $payment_method->slug(), |
|
736 | - 'espresso-button-green button-primary' |
|
737 | - ) |
|
738 | - ) |
|
739 | - ) |
|
740 | - ) |
|
741 | - ), |
|
742 | - ), |
|
743 | - $payment_method |
|
744 | - ), |
|
745 | - ) |
|
746 | - ); |
|
747 | - } |
|
748 | - |
|
749 | - |
|
750 | - /** |
|
751 | - * _fine_print |
|
752 | - * |
|
753 | - * @access protected |
|
754 | - * @return EE_Form_Section_HTML |
|
755 | - */ |
|
756 | - protected function _fine_print() |
|
757 | - { |
|
758 | - return new EE_Form_Section_HTML( |
|
759 | - EEH_HTML::table( |
|
760 | - EEH_HTML::tr( |
|
761 | - EEH_HTML::th() . |
|
762 | - EEH_HTML::td( |
|
763 | - EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text') |
|
764 | - ) |
|
765 | - ) |
|
766 | - ) |
|
767 | - ); |
|
768 | - } |
|
769 | - |
|
770 | - |
|
771 | - /** |
|
772 | - * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far) |
|
773 | - * |
|
774 | - * @global WP_User $current_user |
|
775 | - */ |
|
776 | - protected function _activate_payment_method() |
|
777 | - { |
|
778 | - if (isset($this->_req_data['payment_method_type'])) { |
|
779 | - $payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']); |
|
780 | - // see if one exists |
|
781 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
782 | - $payment_method = EE_Payment_Method_Manager::instance() |
|
783 | - ->activate_a_payment_method_of_type($payment_method_type); |
|
784 | - $this->_redirect_after_action( |
|
785 | - 1, |
|
786 | - 'Payment Method', |
|
787 | - 'activated', |
|
788 | - array('action' => 'default', 'payment_method' => $payment_method->slug()) |
|
789 | - ); |
|
790 | - } else { |
|
791 | - $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default')); |
|
792 | - } |
|
793 | - } |
|
794 | - |
|
795 | - |
|
796 | - /** |
|
797 | - * Deactivates the payment method with the specified slug, and redirects. |
|
798 | - */ |
|
799 | - protected function _deactivate_payment_method() |
|
800 | - { |
|
801 | - if (isset($this->_req_data['payment_method'])) { |
|
802 | - $payment_method_slug = sanitize_key($this->_req_data['payment_method']); |
|
803 | - // deactivate it |
|
804 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
805 | - $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug); |
|
806 | - $this->_redirect_after_action( |
|
807 | - $count_updated, |
|
808 | - 'Payment Method', |
|
809 | - 'deactivated', |
|
810 | - array('action' => 'default', 'payment_method' => $payment_method_slug) |
|
811 | - ); |
|
812 | - } else { |
|
813 | - $this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default')); |
|
814 | - } |
|
815 | - } |
|
816 | - |
|
817 | - |
|
818 | - /** |
|
819 | - * Processes the payment method form that was submitted. This is slightly trickier than usual form |
|
820 | - * processing because we first need to identify WHICH form was processed and which payment method |
|
821 | - * it corresponds to. Once we have done that, we see if the form is valid. If it is, the |
|
822 | - * form's data is saved and we redirect to the default payment methods page, setting the updated payment method |
|
823 | - * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the |
|
824 | - * subsequently called 'headers_sent_func' which is _payment_methods_list) |
|
825 | - * |
|
826 | - * @return void |
|
827 | - */ |
|
828 | - protected function _update_payment_method() |
|
829 | - { |
|
830 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
831 | - // ok let's find which gateway form to use based on the form input |
|
832 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
833 | - /** @var $correct_pmt_form_to_use EE_Payment_Method_Form */ |
|
834 | - $correct_pmt_form_to_use = null; |
|
835 | - $payment_method = null; |
|
836 | - foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) { |
|
837 | - // get the form and simplify it, like what we do when we display it |
|
838 | - $pmt_form = $this->_generate_payment_method_settings_form($payment_method); |
|
839 | - if ($pmt_form->form_data_present_in($this->_req_data)) { |
|
840 | - $correct_pmt_form_to_use = $pmt_form; |
|
841 | - break; |
|
842 | - } |
|
843 | - } |
|
844 | - // if we couldn't find the correct payment method type... |
|
845 | - if (! $correct_pmt_form_to_use) { |
|
846 | - EE_Error::add_error( |
|
847 | - __( |
|
848 | - "We could not find which payment method type your form submission related to. Please contact support", |
|
849 | - 'event_espresso' |
|
850 | - ), |
|
851 | - __FILE__, |
|
852 | - __FUNCTION__, |
|
853 | - __LINE__ |
|
854 | - ); |
|
855 | - $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default')); |
|
856 | - } |
|
857 | - $correct_pmt_form_to_use->receive_form_submission($this->_req_data); |
|
858 | - if ($correct_pmt_form_to_use->is_valid()) { |
|
859 | - $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings'); |
|
860 | - if (! $payment_settings_subform instanceof EE_Payment_Method_Form) { |
|
861 | - throw new EE_Error( |
|
862 | - sprintf( |
|
863 | - __( |
|
864 | - 'The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.', |
|
865 | - 'event_espresso' |
|
866 | - ), |
|
867 | - 'payment_method_settings' |
|
868 | - ) |
|
869 | - ); |
|
870 | - } |
|
871 | - $payment_settings_subform->save(); |
|
872 | - /** @var $pm EE_Payment_Method */ |
|
873 | - $this->_redirect_after_action( |
|
874 | - true, |
|
875 | - 'Payment Method', |
|
876 | - 'updated', |
|
877 | - array('action' => 'default', 'payment_method' => $payment_method->slug()) |
|
878 | - ); |
|
879 | - } else { |
|
880 | - EE_Error::add_error( |
|
881 | - sprintf( |
|
882 | - __( |
|
883 | - 'Payment method of type %s was not saved because there were validation errors. They have been marked in the form', |
|
884 | - 'event_espresso' |
|
885 | - ), |
|
886 | - $payment_method instanceof EE_Payment_Method ? $payment_method->type_obj()->pretty_name() |
|
887 | - : __('"(unknown)"', 'event_espresso') |
|
888 | - ), |
|
889 | - __FILE__, |
|
890 | - __FUNCTION__, |
|
891 | - __LINE__ |
|
892 | - ); |
|
893 | - } |
|
894 | - } |
|
895 | - return; |
|
896 | - } |
|
897 | - |
|
898 | - |
|
899 | - /** |
|
900 | - * Displays payment settings (not payment METHOD settings, that's _payment_method_settings) |
|
901 | - * @throws DomainException |
|
902 | - * @throws EE_Error |
|
903 | - * @throws InvalidArgumentException |
|
904 | - * @throws InvalidDataTypeException |
|
905 | - * @throws InvalidInterfaceException |
|
906 | - */ |
|
907 | - protected function _payment_settings() |
|
908 | - { |
|
909 | - $form = $this->getPaymentSettingsForm(); |
|
910 | - $this->_set_add_edit_form_tags('update_payment_settings'); |
|
911 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
912 | - $this->_template_args['admin_page_content'] = $form->get_html_and_js(); |
|
913 | - $this->display_admin_page_with_sidebar(); |
|
914 | - } |
|
915 | - |
|
916 | - |
|
917 | - /** |
|
918 | - * _update_payment_settings |
|
919 | - * |
|
920 | - * @access protected |
|
921 | - * @return void |
|
922 | - * @throws EE_Error |
|
923 | - * @throws InvalidArgumentException |
|
924 | - * @throws InvalidDataTypeException |
|
925 | - * @throws InvalidInterfaceException |
|
926 | - */ |
|
927 | - protected function _update_payment_settings() |
|
928 | - { |
|
929 | - $form = $this->getPaymentSettingsForm(); |
|
930 | - if ($form->was_submitted($this->_req_data)) { |
|
931 | - $form->receive_form_submission($this->_req_data); |
|
932 | - if ($form->is_valid()) { |
|
933 | - /** |
|
934 | - * @var $reg_config EE_Registration_Config |
|
935 | - */ |
|
936 | - $loader = LoaderFactory::getLoader(); |
|
937 | - $reg_config = $loader->getShared('EE_Registration_Config'); |
|
938 | - $valid_data = $form->valid_data(); |
|
939 | - $reg_config->show_pending_payment_options = $valid_data['show_pending_payment_options']; |
|
940 | - $reg_config->gateway_log_lifespan = $valid_data['gateway_log_lifespan']; |
|
941 | - } |
|
942 | - } |
|
943 | - EE_Registry::instance()->CFG = apply_filters( |
|
944 | - 'FHEE__Payments_Admin_Page___update_payment_settings__CFG', |
|
945 | - EE_Registry::instance()->CFG |
|
946 | - ); |
|
947 | - |
|
948 | - $cfg = EE_Registry::instance()->CFG ; |
|
949 | - |
|
950 | - $what = __('Payment Settings', 'event_espresso'); |
|
951 | - $success = $this->_update_espresso_configuration( |
|
952 | - $what, |
|
953 | - EE_Registry::instance()->CFG, |
|
954 | - __FILE__, |
|
955 | - __FUNCTION__, |
|
956 | - __LINE__ |
|
957 | - ); |
|
958 | - $this->_redirect_after_action( |
|
959 | - $success, |
|
960 | - $what, |
|
961 | - __('updated', 'event_espresso'), |
|
962 | - array('action' => 'payment_settings') |
|
963 | - ); |
|
964 | - } |
|
965 | - |
|
966 | - |
|
967 | - /** |
|
968 | - * Gets the form used for updating payment settings |
|
969 | - * |
|
970 | - * @return EE_Form_Section_Proper |
|
971 | - * @throws EE_Error |
|
972 | - * @throws InvalidArgumentException |
|
973 | - * @throws InvalidDataTypeException |
|
974 | - * @throws InvalidInterfaceException |
|
975 | - */ |
|
976 | - protected function getPaymentSettingsForm() |
|
977 | - { |
|
978 | - /** |
|
979 | - * @var $reg_config EE_Registration_Config |
|
980 | - */ |
|
981 | - $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config'); |
|
982 | - return new EE_Form_Section_Proper( |
|
983 | - array( |
|
984 | - 'name' => 'payment-settings', |
|
985 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
986 | - 'subsections' => array( |
|
987 | - 'show_pending_payment_options' => new EE_Yes_No_Input( |
|
988 | - array( |
|
989 | - 'html_name' => 'show_pending_payment_options', |
|
990 | - 'default' => $reg_config->show_pending_payment_options, |
|
991 | - 'html_help_text' => esc_html__( |
|
992 | - "If a payment is marked as 'Pending Payment', or if payment is deferred (ie, an offline gateway like Check, Bank, or Invoice is used), then give registrants the option to retry payment. ", |
|
993 | - 'event_espresso' |
|
994 | - ) |
|
995 | - ) |
|
996 | - ), |
|
997 | - 'gateway_log_lifespan' => new EE_Select_Input( |
|
998 | - $reg_config->gatewayLogLifespanOptions(), |
|
999 | - array( |
|
1000 | - 'html_label_text' => esc_html__('Gateway Logs Lifespan', 'event_espresso'), |
|
1001 | - 'html_help_text' => esc_html__('If issues arise with payments being made through a payment gateway, it\'s helpful to log non-sensitive communications with the payment gateway. But it\'s a security responsibility, so it\'s a good idea to not keep them for any longer than necessary.', 'event_espresso'), |
|
1002 | - 'default' => $reg_config->gateway_log_lifespan, |
|
1003 | - ) |
|
1004 | - ) |
|
1005 | - ) |
|
1006 | - ) |
|
1007 | - ); |
|
1008 | - } |
|
1009 | - |
|
1010 | - |
|
1011 | - protected function _payment_log_overview_list_table() |
|
1012 | - { |
|
1013 | - $this->display_admin_list_table_page_with_sidebar(); |
|
1014 | - } |
|
1015 | - |
|
1016 | - |
|
1017 | - protected function _set_list_table_views_payment_log() |
|
1018 | - { |
|
1019 | - $this->_views = array( |
|
1020 | - 'all' => array( |
|
1021 | - 'slug' => 'all', |
|
1022 | - 'label' => __('View All Logs', 'event_espresso'), |
|
1023 | - 'count' => 0, |
|
1024 | - ), |
|
1025 | - ); |
|
1026 | - } |
|
1027 | - |
|
1028 | - |
|
1029 | - /** |
|
1030 | - * @param int $per_page |
|
1031 | - * @param int $current_page |
|
1032 | - * @param bool $count |
|
1033 | - * @return array |
|
1034 | - */ |
|
1035 | - public function get_payment_logs($per_page = 50, $current_page = 0, $count = false) |
|
1036 | - { |
|
1037 | - EE_Registry::instance()->load_model('Change_Log'); |
|
1038 | - // we may need to do multiple queries (joining differently), so we actually wan tan array of query params |
|
1039 | - $query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway)); |
|
1040 | - // check if they've selected a specific payment method |
|
1041 | - if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') { |
|
1042 | - $query_params[0]['OR*pm_or_pay_pm'] = array( |
|
1043 | - 'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'], |
|
1044 | - 'Payment_Method.PMD_ID' => $this->_req_data['_payment_method'], |
|
1045 | - ); |
|
1046 | - } |
|
1047 | - // take into account search |
|
1048 | - if (isset($this->_req_data['s']) && $this->_req_data['s']) { |
|
1049 | - $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%'); |
|
1050 | - $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string; |
|
1051 | - $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string; |
|
1052 | - $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string; |
|
1053 | - $query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string; |
|
1054 | - $query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string; |
|
1055 | - $query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string; |
|
1056 | - $query_params[0]['OR*s']['LOG_message'] = $similarity_string; |
|
1057 | - $query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string; |
|
1058 | - $query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string; |
|
1059 | - $query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string; |
|
1060 | - $query_params[0]['OR*s']['LOG_message'] = $similarity_string; |
|
1061 | - } |
|
1062 | - if ( |
|
1063 | - isset($this->_req_data['payment-filter-start-date']) |
|
1064 | - && isset($this->_req_data['payment-filter-end-date']) |
|
1065 | - ) { |
|
1066 | - // add date |
|
1067 | - $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']); |
|
1068 | - $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']); |
|
1069 | - // make sure our timestamps start and end right at the boundaries for each day |
|
1070 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
1071 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
1072 | - // convert to timestamps |
|
1073 | - $start_date = strtotime($start_date); |
|
1074 | - $end_date = strtotime($end_date); |
|
1075 | - // makes sure start date is the lowest value and vice versa |
|
1076 | - $start_date = min($start_date, $end_date); |
|
1077 | - $end_date = max($start_date, $end_date); |
|
1078 | - // convert for query |
|
1079 | - $start_date = EEM_Change_Log::instance() |
|
1080 | - ->convert_datetime_for_query( |
|
1081 | - 'LOG_time', |
|
1082 | - date('Y-m-d H:i:s', $start_date), |
|
1083 | - 'Y-m-d H:i:s' |
|
1084 | - ); |
|
1085 | - $end_date = EEM_Change_Log::instance() |
|
1086 | - ->convert_datetime_for_query( |
|
1087 | - 'LOG_time', |
|
1088 | - date('Y-m-d H:i:s', $end_date), |
|
1089 | - 'Y-m-d H:i:s' |
|
1090 | - ); |
|
1091 | - $query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date)); |
|
1092 | - } |
|
1093 | - if ($count) { |
|
1094 | - return EEM_Change_Log::instance()->count($query_params); |
|
1095 | - } |
|
1096 | - if (isset($this->_req_data['order'])) { |
|
1097 | - $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
1098 | - : 'DESC'; |
|
1099 | - $query_params['order_by'] = array('LOG_time' => $sort); |
|
1100 | - } else { |
|
1101 | - $query_params['order_by'] = array('LOG_time' => 'DESC'); |
|
1102 | - } |
|
1103 | - $offset = ($current_page - 1) * $per_page; |
|
1104 | - if (! isset($this->_req_data['download_results'])) { |
|
1105 | - $query_params['limit'] = array($offset, $per_page); |
|
1106 | - } |
|
1107 | - // now they've requested to instead just download the file instead of viewing it. |
|
1108 | - if (isset($this->_req_data['download_results'])) { |
|
1109 | - $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params); |
|
1110 | - header('Content-Disposition: attachment'); |
|
1111 | - header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url())); |
|
1112 | - echo "<h1>Payment Logs for " . site_url() . "</h1>"; |
|
1113 | - echo "<h3>Query:</h3>"; |
|
1114 | - var_dump($query_params); |
|
1115 | - echo "<h3>Results:</h3>"; |
|
1116 | - var_dump($wpdb_results); |
|
1117 | - die; |
|
1118 | - } |
|
1119 | - $results = EEM_Change_Log::instance()->get_all($query_params); |
|
1120 | - return $results; |
|
1121 | - } |
|
1122 | - |
|
1123 | - |
|
1124 | - /** |
|
1125 | - * Used by usort to RE-sort log query results, because we lose the ordering |
|
1126 | - * because we're possibly combining the results from two queries |
|
1127 | - * |
|
1128 | - * @param EE_Change_Log $logA |
|
1129 | - * @param EE_Change_Log $logB |
|
1130 | - * @return int |
|
1131 | - */ |
|
1132 | - protected function _sort_logs_again($logA, $logB) |
|
1133 | - { |
|
1134 | - $timeA = $logA->get_raw('LOG_time'); |
|
1135 | - $timeB = $logB->get_raw('LOG_time'); |
|
1136 | - if ($timeA == $timeB) { |
|
1137 | - return 0; |
|
1138 | - } |
|
1139 | - $comparison = $timeA < $timeB ? -1 : 1; |
|
1140 | - if (strtoupper($this->_sort_logs_again_direction) == 'DESC') { |
|
1141 | - return $comparison * -1; |
|
1142 | - } else { |
|
1143 | - return $comparison; |
|
1144 | - } |
|
1145 | - } |
|
1146 | - |
|
1147 | - |
|
1148 | - protected function _payment_log_details() |
|
1149 | - { |
|
1150 | - EE_Registry::instance()->load_model('Change_Log'); |
|
1151 | - /** @var $payment_log EE_Change_Log */ |
|
1152 | - $payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']); |
|
1153 | - $payment_method = null; |
|
1154 | - $transaction = null; |
|
1155 | - if ($payment_log instanceof EE_Change_Log) { |
|
1156 | - if ($payment_log->object() instanceof EE_Payment) { |
|
1157 | - $payment_method = $payment_log->object()->payment_method(); |
|
1158 | - $transaction = $payment_log->object()->transaction(); |
|
1159 | - } elseif ($payment_log->object() instanceof EE_Payment_Method) { |
|
1160 | - $payment_method = $payment_log->object(); |
|
1161 | - } elseif ($payment_log->object() instanceof EE_Transaction) { |
|
1162 | - $transaction = $payment_log->object(); |
|
1163 | - $payment_method = $transaction->payment_method(); |
|
1164 | - } |
|
1165 | - } |
|
1166 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
1167 | - EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php', |
|
1168 | - array( |
|
1169 | - 'payment_log' => $payment_log, |
|
1170 | - 'payment_method' => $payment_method, |
|
1171 | - 'transaction' => $transaction, |
|
1172 | - ), |
|
1173 | - true |
|
1174 | - ); |
|
1175 | - $this->display_admin_page_with_no_sidebar(); |
|
1176 | - } |
|
19 | + /** |
|
20 | + * Variables used for when we're re-sorting the logs results, in case |
|
21 | + * we needed to do two queries and we need to resort |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + private $_sort_logs_again_direction; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @Constructor |
|
30 | + * @access public |
|
31 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
32 | + * @throws EE_Error |
|
33 | + * @throws InvalidArgumentException |
|
34 | + * @throws InvalidDataTypeException |
|
35 | + * @throws InvalidInterfaceException |
|
36 | + * @throws ReflectionException |
|
37 | + */ |
|
38 | + public function __construct($routing = true) |
|
39 | + { |
|
40 | + parent::__construct($routing); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + protected function _init_page_props() |
|
45 | + { |
|
46 | + $this->page_slug = EE_PAYMENTS_PG_SLUG; |
|
47 | + $this->page_label = __('Payment Methods', 'event_espresso'); |
|
48 | + $this->_admin_base_url = EE_PAYMENTS_ADMIN_URL; |
|
49 | + $this->_admin_base_path = EE_PAYMENTS_ADMIN; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + protected function _ajax_hooks() |
|
54 | + { |
|
55 | + // todo: all hooks for ajax goes here. |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + protected function _define_page_props() |
|
60 | + { |
|
61 | + $this->_admin_page_title = $this->page_label; |
|
62 | + $this->_labels = array( |
|
63 | + 'publishbox' => __('Update Settings', 'event_espresso'), |
|
64 | + ); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + protected function _set_page_routes() |
|
69 | + { |
|
70 | + /** |
|
71 | + * note that with payment method capabilities, although we've implemented |
|
72 | + * capability mapping which will be used for accessing payment methods owned by |
|
73 | + * other users. This is not fully implemented yet in the payment method ui. |
|
74 | + * Currently only the "plural" caps are in active use. |
|
75 | + * When cap mapping is implemented, some routes will need to use the singular form of |
|
76 | + * capability method and also include the $id of the payment method for the route. |
|
77 | + **/ |
|
78 | + $this->_page_routes = array( |
|
79 | + 'default' => array( |
|
80 | + 'func' => '_payment_methods_list', |
|
81 | + 'capability' => 'ee_edit_payment_methods', |
|
82 | + ), |
|
83 | + 'payment_settings' => array( |
|
84 | + 'func' => '_payment_settings', |
|
85 | + 'capability' => 'ee_manage_gateways', |
|
86 | + ), |
|
87 | + 'activate_payment_method' => array( |
|
88 | + 'func' => '_activate_payment_method', |
|
89 | + 'noheader' => true, |
|
90 | + 'capability' => 'ee_edit_payment_methods', |
|
91 | + ), |
|
92 | + 'deactivate_payment_method' => array( |
|
93 | + 'func' => '_deactivate_payment_method', |
|
94 | + 'noheader' => true, |
|
95 | + 'capability' => 'ee_delete_payment_methods', |
|
96 | + ), |
|
97 | + 'update_payment_method' => array( |
|
98 | + 'func' => '_update_payment_method', |
|
99 | + 'noheader' => true, |
|
100 | + 'headers_sent_route' => 'default', |
|
101 | + 'capability' => 'ee_edit_payment_methods', |
|
102 | + ), |
|
103 | + 'update_payment_settings' => array( |
|
104 | + 'func' => '_update_payment_settings', |
|
105 | + 'noheader' => true, |
|
106 | + 'capability' => 'ee_manage_gateways', |
|
107 | + ), |
|
108 | + 'payment_log' => array( |
|
109 | + 'func' => '_payment_log_overview_list_table', |
|
110 | + 'capability' => 'ee_read_payment_methods', |
|
111 | + ), |
|
112 | + 'payment_log_details' => array( |
|
113 | + 'func' => '_payment_log_details', |
|
114 | + 'capability' => 'ee_read_payment_methods', |
|
115 | + ), |
|
116 | + ); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + protected function _set_page_config() |
|
121 | + { |
|
122 | + $payment_method_list_config = array( |
|
123 | + 'nav' => array( |
|
124 | + 'label' => __('Payment Methods', 'event_espresso'), |
|
125 | + 'order' => 10, |
|
126 | + ), |
|
127 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
128 | + 'help_tabs' => array_merge( |
|
129 | + array( |
|
130 | + 'payment_methods_overview_help_tab' => array( |
|
131 | + 'title' => __('Payment Methods Overview', 'event_espresso'), |
|
132 | + 'filename' => 'payment_methods_overview', |
|
133 | + ), |
|
134 | + ), |
|
135 | + $this->_add_payment_method_help_tabs() |
|
136 | + ), |
|
137 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
138 | + // 'help_tour' => array('Payment_Methods_Selection_Help_Tour'), |
|
139 | + 'require_nonce' => false, |
|
140 | + ); |
|
141 | + $this->_page_config = array( |
|
142 | + 'default' => $payment_method_list_config, |
|
143 | + 'payment_settings' => array( |
|
144 | + 'nav' => array( |
|
145 | + 'label' => __('Settings', 'event_espresso'), |
|
146 | + 'order' => 20, |
|
147 | + ), |
|
148 | + 'help_tabs' => array( |
|
149 | + 'payment_methods_settings_help_tab' => array( |
|
150 | + 'title' => __('Payment Method Settings', 'event_espresso'), |
|
151 | + 'filename' => 'payment_methods_settings', |
|
152 | + ), |
|
153 | + ), |
|
154 | + // 'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ), |
|
155 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
156 | + 'require_nonce' => false, |
|
157 | + ), |
|
158 | + 'payment_log' => array( |
|
159 | + 'nav' => array( |
|
160 | + 'label' => __("Logs", 'event_espresso'), |
|
161 | + 'order' => 30, |
|
162 | + ), |
|
163 | + 'list_table' => 'Payment_Log_Admin_List_Table', |
|
164 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
165 | + 'require_nonce' => false, |
|
166 | + ), |
|
167 | + ); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @return array |
|
173 | + * @throws DomainException |
|
174 | + * @throws EE_Error |
|
175 | + * @throws InvalidArgumentException |
|
176 | + * @throws InvalidDataTypeException |
|
177 | + * @throws InvalidInterfaceException |
|
178 | + * @throws ReflectionException |
|
179 | + */ |
|
180 | + protected function _add_payment_method_help_tabs() |
|
181 | + { |
|
182 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
183 | + $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types(); |
|
184 | + $all_pmt_help_tabs_config = array(); |
|
185 | + foreach ($payment_method_types as $payment_method_type) { |
|
186 | + if ( |
|
187 | + ! EE_Registry::instance()->CAP->current_user_can( |
|
188 | + $payment_method_type->cap_name(), |
|
189 | + 'specific_payment_method_type_access' |
|
190 | + ) |
|
191 | + ) { |
|
192 | + continue; |
|
193 | + } |
|
194 | + foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) { |
|
195 | + $template_args = isset($config['template_args']) ? $config['template_args'] : array(); |
|
196 | + $template_args['admin_page_obj'] = $this; |
|
197 | + $all_pmt_help_tabs_config[ $help_tab_name ] = array( |
|
198 | + 'title' => $config['title'], |
|
199 | + 'content' => EEH_Template::display_template( |
|
200 | + $payment_method_type->file_folder() . 'help_tabs/' . $config['filename'] . '.help_tab.php', |
|
201 | + $template_args, |
|
202 | + true |
|
203 | + ), |
|
204 | + ); |
|
205 | + } |
|
206 | + } |
|
207 | + return $all_pmt_help_tabs_config; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + // none of the below group are currently used for Gateway Settings |
|
212 | + protected function _add_screen_options() |
|
213 | + { |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + protected function _add_feature_pointers() |
|
218 | + { |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + public function admin_init() |
|
223 | + { |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + public function admin_notices() |
|
228 | + { |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + public function admin_footer_scripts() |
|
233 | + { |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + public function load_scripts_styles() |
|
238 | + { |
|
239 | + // styles |
|
240 | + wp_enqueue_style('espresso-ui-theme'); |
|
241 | + wp_register_style( |
|
242 | + 'espresso_payments', |
|
243 | + EE_PAYMENTS_ASSETS_URL . 'ee-payments.css', |
|
244 | + [], |
|
245 | + EVENT_ESPRESSO_VERSION |
|
246 | + ); |
|
247 | + // scripts |
|
248 | + wp_enqueue_script('ee_admin_js'); |
|
249 | + wp_enqueue_script('ee-text-links'); |
|
250 | + wp_enqueue_script( |
|
251 | + 'espresso_payments', |
|
252 | + EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js', |
|
253 | + ['ee-datepicker'], |
|
254 | + EVENT_ESPRESSO_VERSION, |
|
255 | + true |
|
256 | + ); |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + public function load_scripts_styles_default() |
|
261 | + { |
|
262 | + wp_enqueue_style('espresso_payments'); |
|
263 | + wp_enqueue_style('ee-text-links'); |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + public function load_scripts_styles_payment_log_details() |
|
268 | + { |
|
269 | + wp_enqueue_style('espresso_payments'); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + protected function _payment_methods_list() |
|
274 | + { |
|
275 | + /** |
|
276 | + * first let's ensure payment methods have been setup. We do this here because when people activate a |
|
277 | + * payment method for the first time (as an addon), it may not setup its capabilities or get registered |
|
278 | + * correctly due to the loading process. However, people MUST setup the details for the payment method so its |
|
279 | + * safe to do a recheck here. |
|
280 | + */ |
|
281 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
282 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
283 | + // setup tabs, one for each payment method type |
|
284 | + $tabs = array(); |
|
285 | + $payment_methods = array(); |
|
286 | + foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) { |
|
287 | + // we don't want to show admin-only PMTs for now |
|
288 | + if ($pmt_obj instanceof EE_PMT_Admin_Only) { |
|
289 | + continue; |
|
290 | + } |
|
291 | + // check access |
|
292 | + if ( |
|
293 | + ! EE_Registry::instance()->CAP->current_user_can( |
|
294 | + $pmt_obj->cap_name(), |
|
295 | + 'specific_payment_method_type_access' |
|
296 | + ) |
|
297 | + ) { |
|
298 | + continue; |
|
299 | + } |
|
300 | + // check for any active pms of that type |
|
301 | + $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name()); |
|
302 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
303 | + $payment_method = EE_Payment_Method::new_instance( |
|
304 | + array( |
|
305 | + 'PMD_slug' => sanitize_key($pmt_obj->system_name()), |
|
306 | + 'PMD_type' => $pmt_obj->system_name(), |
|
307 | + 'PMD_name' => $pmt_obj->pretty_name(), |
|
308 | + 'PMD_admin_name' => $pmt_obj->pretty_name(), |
|
309 | + ) |
|
310 | + ); |
|
311 | + } |
|
312 | + $payment_methods[ $payment_method->slug() ] = $payment_method; |
|
313 | + } |
|
314 | + $payment_methods = apply_filters( |
|
315 | + 'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', |
|
316 | + $payment_methods |
|
317 | + ); |
|
318 | + foreach ($payment_methods as $payment_method) { |
|
319 | + if ($payment_method instanceof EE_Payment_Method) { |
|
320 | + add_meta_box( |
|
321 | + // html id |
|
322 | + 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
323 | + // title |
|
324 | + sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()), |
|
325 | + // callback |
|
326 | + array($this, 'payment_method_settings_meta_box'), |
|
327 | + // post type |
|
328 | + null, |
|
329 | + // context |
|
330 | + 'normal', |
|
331 | + // priority |
|
332 | + 'default', |
|
333 | + // callback args |
|
334 | + array('payment_method' => $payment_method) |
|
335 | + ); |
|
336 | + // setup for tabbed content |
|
337 | + $tabs[ $payment_method->slug() ] = array( |
|
338 | + 'label' => $payment_method->admin_name(), |
|
339 | + 'class' => $payment_method->active() ? 'gateway-active' : '', |
|
340 | + 'href' => 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
341 | + 'title' => __('Modify this Payment Method', 'event_espresso'), |
|
342 | + 'slug' => $payment_method->slug(), |
|
343 | + ); |
|
344 | + } |
|
345 | + } |
|
346 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
347 | + $tabs, |
|
348 | + 'payment_method_links', |
|
349 | + '|', |
|
350 | + $this->_get_active_payment_method_slug() |
|
351 | + ); |
|
352 | + $this->display_admin_page_with_sidebar(); |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * _get_active_payment_method_slug |
|
358 | + * |
|
359 | + * @return string |
|
360 | + */ |
|
361 | + protected function _get_active_payment_method_slug() |
|
362 | + { |
|
363 | + $payment_method_slug = false; |
|
364 | + // decide which payment method tab to open first, as dictated by the request's 'payment_method' |
|
365 | + if (isset($this->_req_data['payment_method'])) { |
|
366 | + // if they provided the current payment method, use it |
|
367 | + $payment_method_slug = sanitize_key($this->_req_data['payment_method']); |
|
368 | + } |
|
369 | + $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug))); |
|
370 | + // if that didn't work or wasn't provided, find another way to select the current pm |
|
371 | + if (! $this->_verify_payment_method($payment_method)) { |
|
372 | + // like, looking for an active one |
|
373 | + $payment_method = EEM_Payment_Method::instance()->get_one_active('CART'); |
|
374 | + // test that one as well |
|
375 | + if ($this->_verify_payment_method($payment_method)) { |
|
376 | + $payment_method_slug = $payment_method->slug(); |
|
377 | + } else { |
|
378 | + $payment_method_slug = 'paypal_standard'; |
|
379 | + } |
|
380 | + } |
|
381 | + return $payment_method_slug; |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * payment_method_settings_meta_box |
|
387 | + * returns TRUE if the passed payment method is properly constructed and the logged in user has the correct |
|
388 | + * capabilities to access it |
|
389 | + * |
|
390 | + * @param EE_Payment_Method $payment_method |
|
391 | + * @return boolean |
|
392 | + */ |
|
393 | + protected function _verify_payment_method($payment_method) |
|
394 | + { |
|
395 | + if ( |
|
396 | + $payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base |
|
397 | + && EE_Registry::instance()->CAP->current_user_can( |
|
398 | + $payment_method->type_obj()->cap_name(), |
|
399 | + 'specific_payment_method_type_access' |
|
400 | + ) |
|
401 | + ) { |
|
402 | + return true; |
|
403 | + } |
|
404 | + return false; |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * payment_method_settings_meta_box |
|
410 | + * |
|
411 | + * @param NULL $post_obj_which_is_null is an object containing the current post (as a $post object) |
|
412 | + * @param array $metabox is an array with metabox id, title, callback, and args elements. the value |
|
413 | + * at 'args' has key 'payment_method', as set within _payment_methods_list |
|
414 | + * @return string |
|
415 | + * @throws EE_Error |
|
416 | + */ |
|
417 | + public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox) |
|
418 | + { |
|
419 | + $payment_method = isset($metabox['args'], $metabox['args']['payment_method']) |
|
420 | + ? $metabox['args']['payment_method'] : null; |
|
421 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
422 | + throw new EE_Error( |
|
423 | + sprintf( |
|
424 | + __( |
|
425 | + 'Payment method metabox setup incorrectly. No Payment method object was supplied', |
|
426 | + 'event_espresso' |
|
427 | + ) |
|
428 | + ) |
|
429 | + ); |
|
430 | + } |
|
431 | + $payment_method_scopes = $payment_method->active(); |
|
432 | + // if the payment method really exists show its form, otherwise the activation template |
|
433 | + if ($payment_method->ID() && ! empty($payment_method_scopes)) { |
|
434 | + $form = $this->_generate_payment_method_settings_form($payment_method); |
|
435 | + if ($form->form_data_present_in($this->_req_data)) { |
|
436 | + $form->receive_form_submission($this->_req_data); |
|
437 | + } |
|
438 | + echo $form->form_open() . $form->get_html_and_js() . $form->form_close(); |
|
439 | + } else { |
|
440 | + echo $this->_activate_payment_method_button($payment_method)->get_html_and_js(); |
|
441 | + } |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * Gets the form for all the settings related to this payment method type |
|
447 | + * |
|
448 | + * @access protected |
|
449 | + * @param EE_Payment_Method $payment_method |
|
450 | + * @return EE_Form_Section_Proper |
|
451 | + */ |
|
452 | + protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method) |
|
453 | + { |
|
454 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
455 | + return new EE_Form_Section_Proper(); |
|
456 | + } |
|
457 | + return new EE_Form_Section_Proper( |
|
458 | + array( |
|
459 | + 'name' => $payment_method->slug() . '_settings_form', |
|
460 | + 'html_id' => $payment_method->slug() . '_settings_form', |
|
461 | + 'action' => EE_Admin_Page::add_query_args_and_nonce( |
|
462 | + array( |
|
463 | + 'action' => 'update_payment_method', |
|
464 | + 'payment_method' => $payment_method->slug(), |
|
465 | + ), |
|
466 | + EE_PAYMENTS_ADMIN_URL |
|
467 | + ), |
|
468 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
469 | + 'subsections' => apply_filters( |
|
470 | + 'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections', |
|
471 | + array( |
|
472 | + 'pci_dss_compliance' => $this->_pci_dss_compliance($payment_method), |
|
473 | + 'currency_support' => $this->_currency_support($payment_method), |
|
474 | + 'payment_method_settings' => $this->_payment_method_settings($payment_method), |
|
475 | + 'update' => $this->_update_payment_method_button($payment_method), |
|
476 | + 'deactivate' => $this->_deactivate_payment_method_button($payment_method), |
|
477 | + 'fine_print' => $this->_fine_print(), |
|
478 | + ), |
|
479 | + $payment_method |
|
480 | + ), |
|
481 | + ) |
|
482 | + ); |
|
483 | + } |
|
484 | + |
|
485 | + |
|
486 | + /** |
|
487 | + * _pci_dss_compliance |
|
488 | + * |
|
489 | + * @access protected |
|
490 | + * @param EE_Payment_Method $payment_method |
|
491 | + * @return EE_Form_Section_Proper |
|
492 | + */ |
|
493 | + protected function _pci_dss_compliance(EE_Payment_Method $payment_method) |
|
494 | + { |
|
495 | + if ($payment_method->type_obj()->requires_https()) { |
|
496 | + return new EE_Form_Section_HTML( |
|
497 | + EEH_HTML::table( |
|
498 | + EEH_HTML::tr( |
|
499 | + EEH_HTML::th( |
|
500 | + EEH_HTML::label( |
|
501 | + EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
|
502 | + ) |
|
503 | + ) . |
|
504 | + EEH_HTML::td( |
|
505 | + EEH_HTML::strong( |
|
506 | + __( |
|
507 | + 'You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.', |
|
508 | + 'event_espresso' |
|
509 | + ) |
|
510 | + ) |
|
511 | + . |
|
512 | + EEH_HTML::br() |
|
513 | + . |
|
514 | + __('Learn more about ', 'event_espresso') |
|
515 | + . EEH_HTML::link( |
|
516 | + 'https://www.pcisecuritystandards.org/merchants/index.php', |
|
517 | + __('PCI DSS compliance', 'event_espresso') |
|
518 | + ) |
|
519 | + ) |
|
520 | + ) |
|
521 | + ) |
|
522 | + ); |
|
523 | + } else { |
|
524 | + return new EE_Form_Section_HTML(''); |
|
525 | + } |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * _currency_support |
|
531 | + * |
|
532 | + * @access protected |
|
533 | + * @param EE_Payment_Method $payment_method |
|
534 | + * @return EE_Form_Section_Proper |
|
535 | + */ |
|
536 | + protected function _currency_support(EE_Payment_Method $payment_method) |
|
537 | + { |
|
538 | + if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) { |
|
539 | + return new EE_Form_Section_HTML( |
|
540 | + EEH_HTML::table( |
|
541 | + EEH_HTML::tr( |
|
542 | + EEH_HTML::th( |
|
543 | + EEH_HTML::label( |
|
544 | + EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
|
545 | + ) |
|
546 | + ) . |
|
547 | + EEH_HTML::td( |
|
548 | + EEH_HTML::strong( |
|
549 | + sprintf( |
|
550 | + __( |
|
551 | + 'This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.', |
|
552 | + 'event_espresso' |
|
553 | + ), |
|
554 | + EE_Config::instance()->currency->code |
|
555 | + ) |
|
556 | + ) |
|
557 | + ) |
|
558 | + ) |
|
559 | + ) |
|
560 | + ); |
|
561 | + } else { |
|
562 | + return new EE_Form_Section_HTML(''); |
|
563 | + } |
|
564 | + } |
|
565 | + |
|
566 | + |
|
567 | + /** |
|
568 | + * _update_payment_method_button |
|
569 | + * |
|
570 | + * @access protected |
|
571 | + * @param EE_Payment_Method $payment_method |
|
572 | + * @return EE_Payment_Method_Form |
|
573 | + */ |
|
574 | + protected function _payment_method_settings(EE_Payment_Method $payment_method) |
|
575 | + { |
|
576 | + // modify the form so we only have/show fields that will be implemented for this version |
|
577 | + return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name()); |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + /** |
|
582 | + * Simplifies the form to merely reproduce 4.1's gateway settings functionality |
|
583 | + * |
|
584 | + * @param EE_Form_Section_Proper $form_section |
|
585 | + * @param string $payment_method_name |
|
586 | + * @return EE_Payment_Method_Form |
|
587 | + * @throws EE_Error |
|
588 | + */ |
|
589 | + protected function _simplify_form($form_section, $payment_method_name = '') |
|
590 | + { |
|
591 | + if ($form_section instanceof EE_Payment_Method_Form) { |
|
592 | + $form_section->exclude( |
|
593 | + array( |
|
594 | + 'PMD_type', // dont want them changing the type |
|
595 | + 'PMD_slug', // or the slug (probably never) |
|
596 | + 'PMD_wp_user', // or the user's ID |
|
597 | + 'Currency' // or the currency, until the rest of EE supports simultaneous currencies |
|
598 | + ) |
|
599 | + ); |
|
600 | + return $form_section; |
|
601 | + } else { |
|
602 | + throw new EE_Error( |
|
603 | + sprintf( |
|
604 | + __( |
|
605 | + 'The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.', |
|
606 | + 'event_espresso' |
|
607 | + ), |
|
608 | + $payment_method_name |
|
609 | + ) |
|
610 | + ); |
|
611 | + } |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + /** |
|
616 | + * _update_payment_method_button |
|
617 | + * |
|
618 | + * @access protected |
|
619 | + * @param EE_Payment_Method $payment_method |
|
620 | + * @return EE_Form_Section_HTML |
|
621 | + */ |
|
622 | + protected function _update_payment_method_button(EE_Payment_Method $payment_method) |
|
623 | + { |
|
624 | + $update_button = new EE_Submit_Input( |
|
625 | + array( |
|
626 | + 'name' => 'submit', |
|
627 | + 'html_id' => 'save_' . $payment_method->slug() . '_settings', |
|
628 | + 'default' => sprintf( |
|
629 | + __('Update %s Payment Settings', 'event_espresso'), |
|
630 | + $payment_method->admin_name() |
|
631 | + ), |
|
632 | + 'html_label' => EEH_HTML::nbsp(), |
|
633 | + ) |
|
634 | + ); |
|
635 | + return new EE_Form_Section_HTML( |
|
636 | + EEH_HTML::table( |
|
637 | + EEH_HTML::no_row(EEH_HTML::br(2)) . |
|
638 | + EEH_HTML::tr( |
|
639 | + EEH_HTML::th(__('Update Settings', 'event_espresso')) . |
|
640 | + EEH_HTML::td( |
|
641 | + $update_button->get_html_for_input() |
|
642 | + ) |
|
643 | + ) |
|
644 | + ) |
|
645 | + ); |
|
646 | + } |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * _deactivate_payment_method_button |
|
651 | + * |
|
652 | + * @access protected |
|
653 | + * @param EE_Payment_Method $payment_method |
|
654 | + * @return EE_Form_Section_Proper |
|
655 | + */ |
|
656 | + protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method) |
|
657 | + { |
|
658 | + $link_text_and_title = sprintf( |
|
659 | + __('Deactivate %1$s Payments?', 'event_espresso'), |
|
660 | + $payment_method->admin_name() |
|
661 | + ); |
|
662 | + return new EE_Form_Section_HTML( |
|
663 | + EEH_HTML::table( |
|
664 | + EEH_HTML::tr( |
|
665 | + EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) . |
|
666 | + EEH_HTML::td( |
|
667 | + EEH_HTML::link( |
|
668 | + EE_Admin_Page::add_query_args_and_nonce( |
|
669 | + array( |
|
670 | + 'action' => 'deactivate_payment_method', |
|
671 | + 'payment_method' => $payment_method->slug(), |
|
672 | + ), |
|
673 | + EE_PAYMENTS_ADMIN_URL |
|
674 | + ), |
|
675 | + $link_text_and_title, |
|
676 | + $link_text_and_title, |
|
677 | + 'deactivate_' . $payment_method->slug(), |
|
678 | + 'espresso-button button-secondary' |
|
679 | + ) |
|
680 | + ) |
|
681 | + ) |
|
682 | + ) |
|
683 | + ); |
|
684 | + } |
|
685 | + |
|
686 | + |
|
687 | + /** |
|
688 | + * _activate_payment_method_button |
|
689 | + * |
|
690 | + * @access protected |
|
691 | + * @param EE_Payment_Method $payment_method |
|
692 | + * @return EE_Form_Section_Proper |
|
693 | + */ |
|
694 | + protected function _activate_payment_method_button(EE_Payment_Method $payment_method) |
|
695 | + { |
|
696 | + $link_text_and_title = sprintf( |
|
697 | + __('Activate %1$s Payment Method?', 'event_espresso'), |
|
698 | + $payment_method->admin_name() |
|
699 | + ); |
|
700 | + return new EE_Form_Section_Proper( |
|
701 | + array( |
|
702 | + 'name' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
703 | + 'html_id' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
704 | + 'action' => '#', |
|
705 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
706 | + 'subsections' => apply_filters( |
|
707 | + 'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections', |
|
708 | + array( |
|
709 | + new EE_Form_Section_HTML( |
|
710 | + EEH_HTML::table( |
|
711 | + EEH_HTML::tr( |
|
712 | + EEH_HTML::td( |
|
713 | + $payment_method->type_obj()->introductory_html(), |
|
714 | + '', |
|
715 | + '', |
|
716 | + '', |
|
717 | + 'colspan="2"' |
|
718 | + ) |
|
719 | + ) . |
|
720 | + EEH_HTML::tr( |
|
721 | + EEH_HTML::th( |
|
722 | + EEH_HTML::label(__('Click to Activate ', 'event_espresso')) |
|
723 | + ) . |
|
724 | + EEH_HTML::td( |
|
725 | + EEH_HTML::link( |
|
726 | + EE_Admin_Page::add_query_args_and_nonce( |
|
727 | + array( |
|
728 | + 'action' => 'activate_payment_method', |
|
729 | + 'payment_method_type' => $payment_method->type(), |
|
730 | + ), |
|
731 | + EE_PAYMENTS_ADMIN_URL |
|
732 | + ), |
|
733 | + $link_text_and_title, |
|
734 | + $link_text_and_title, |
|
735 | + 'activate_' . $payment_method->slug(), |
|
736 | + 'espresso-button-green button-primary' |
|
737 | + ) |
|
738 | + ) |
|
739 | + ) |
|
740 | + ) |
|
741 | + ), |
|
742 | + ), |
|
743 | + $payment_method |
|
744 | + ), |
|
745 | + ) |
|
746 | + ); |
|
747 | + } |
|
748 | + |
|
749 | + |
|
750 | + /** |
|
751 | + * _fine_print |
|
752 | + * |
|
753 | + * @access protected |
|
754 | + * @return EE_Form_Section_HTML |
|
755 | + */ |
|
756 | + protected function _fine_print() |
|
757 | + { |
|
758 | + return new EE_Form_Section_HTML( |
|
759 | + EEH_HTML::table( |
|
760 | + EEH_HTML::tr( |
|
761 | + EEH_HTML::th() . |
|
762 | + EEH_HTML::td( |
|
763 | + EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text') |
|
764 | + ) |
|
765 | + ) |
|
766 | + ) |
|
767 | + ); |
|
768 | + } |
|
769 | + |
|
770 | + |
|
771 | + /** |
|
772 | + * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far) |
|
773 | + * |
|
774 | + * @global WP_User $current_user |
|
775 | + */ |
|
776 | + protected function _activate_payment_method() |
|
777 | + { |
|
778 | + if (isset($this->_req_data['payment_method_type'])) { |
|
779 | + $payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']); |
|
780 | + // see if one exists |
|
781 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
782 | + $payment_method = EE_Payment_Method_Manager::instance() |
|
783 | + ->activate_a_payment_method_of_type($payment_method_type); |
|
784 | + $this->_redirect_after_action( |
|
785 | + 1, |
|
786 | + 'Payment Method', |
|
787 | + 'activated', |
|
788 | + array('action' => 'default', 'payment_method' => $payment_method->slug()) |
|
789 | + ); |
|
790 | + } else { |
|
791 | + $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default')); |
|
792 | + } |
|
793 | + } |
|
794 | + |
|
795 | + |
|
796 | + /** |
|
797 | + * Deactivates the payment method with the specified slug, and redirects. |
|
798 | + */ |
|
799 | + protected function _deactivate_payment_method() |
|
800 | + { |
|
801 | + if (isset($this->_req_data['payment_method'])) { |
|
802 | + $payment_method_slug = sanitize_key($this->_req_data['payment_method']); |
|
803 | + // deactivate it |
|
804 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
805 | + $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug); |
|
806 | + $this->_redirect_after_action( |
|
807 | + $count_updated, |
|
808 | + 'Payment Method', |
|
809 | + 'deactivated', |
|
810 | + array('action' => 'default', 'payment_method' => $payment_method_slug) |
|
811 | + ); |
|
812 | + } else { |
|
813 | + $this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default')); |
|
814 | + } |
|
815 | + } |
|
816 | + |
|
817 | + |
|
818 | + /** |
|
819 | + * Processes the payment method form that was submitted. This is slightly trickier than usual form |
|
820 | + * processing because we first need to identify WHICH form was processed and which payment method |
|
821 | + * it corresponds to. Once we have done that, we see if the form is valid. If it is, the |
|
822 | + * form's data is saved and we redirect to the default payment methods page, setting the updated payment method |
|
823 | + * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the |
|
824 | + * subsequently called 'headers_sent_func' which is _payment_methods_list) |
|
825 | + * |
|
826 | + * @return void |
|
827 | + */ |
|
828 | + protected function _update_payment_method() |
|
829 | + { |
|
830 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
831 | + // ok let's find which gateway form to use based on the form input |
|
832 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
833 | + /** @var $correct_pmt_form_to_use EE_Payment_Method_Form */ |
|
834 | + $correct_pmt_form_to_use = null; |
|
835 | + $payment_method = null; |
|
836 | + foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) { |
|
837 | + // get the form and simplify it, like what we do when we display it |
|
838 | + $pmt_form = $this->_generate_payment_method_settings_form($payment_method); |
|
839 | + if ($pmt_form->form_data_present_in($this->_req_data)) { |
|
840 | + $correct_pmt_form_to_use = $pmt_form; |
|
841 | + break; |
|
842 | + } |
|
843 | + } |
|
844 | + // if we couldn't find the correct payment method type... |
|
845 | + if (! $correct_pmt_form_to_use) { |
|
846 | + EE_Error::add_error( |
|
847 | + __( |
|
848 | + "We could not find which payment method type your form submission related to. Please contact support", |
|
849 | + 'event_espresso' |
|
850 | + ), |
|
851 | + __FILE__, |
|
852 | + __FUNCTION__, |
|
853 | + __LINE__ |
|
854 | + ); |
|
855 | + $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default')); |
|
856 | + } |
|
857 | + $correct_pmt_form_to_use->receive_form_submission($this->_req_data); |
|
858 | + if ($correct_pmt_form_to_use->is_valid()) { |
|
859 | + $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings'); |
|
860 | + if (! $payment_settings_subform instanceof EE_Payment_Method_Form) { |
|
861 | + throw new EE_Error( |
|
862 | + sprintf( |
|
863 | + __( |
|
864 | + 'The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.', |
|
865 | + 'event_espresso' |
|
866 | + ), |
|
867 | + 'payment_method_settings' |
|
868 | + ) |
|
869 | + ); |
|
870 | + } |
|
871 | + $payment_settings_subform->save(); |
|
872 | + /** @var $pm EE_Payment_Method */ |
|
873 | + $this->_redirect_after_action( |
|
874 | + true, |
|
875 | + 'Payment Method', |
|
876 | + 'updated', |
|
877 | + array('action' => 'default', 'payment_method' => $payment_method->slug()) |
|
878 | + ); |
|
879 | + } else { |
|
880 | + EE_Error::add_error( |
|
881 | + sprintf( |
|
882 | + __( |
|
883 | + 'Payment method of type %s was not saved because there were validation errors. They have been marked in the form', |
|
884 | + 'event_espresso' |
|
885 | + ), |
|
886 | + $payment_method instanceof EE_Payment_Method ? $payment_method->type_obj()->pretty_name() |
|
887 | + : __('"(unknown)"', 'event_espresso') |
|
888 | + ), |
|
889 | + __FILE__, |
|
890 | + __FUNCTION__, |
|
891 | + __LINE__ |
|
892 | + ); |
|
893 | + } |
|
894 | + } |
|
895 | + return; |
|
896 | + } |
|
897 | + |
|
898 | + |
|
899 | + /** |
|
900 | + * Displays payment settings (not payment METHOD settings, that's _payment_method_settings) |
|
901 | + * @throws DomainException |
|
902 | + * @throws EE_Error |
|
903 | + * @throws InvalidArgumentException |
|
904 | + * @throws InvalidDataTypeException |
|
905 | + * @throws InvalidInterfaceException |
|
906 | + */ |
|
907 | + protected function _payment_settings() |
|
908 | + { |
|
909 | + $form = $this->getPaymentSettingsForm(); |
|
910 | + $this->_set_add_edit_form_tags('update_payment_settings'); |
|
911 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
912 | + $this->_template_args['admin_page_content'] = $form->get_html_and_js(); |
|
913 | + $this->display_admin_page_with_sidebar(); |
|
914 | + } |
|
915 | + |
|
916 | + |
|
917 | + /** |
|
918 | + * _update_payment_settings |
|
919 | + * |
|
920 | + * @access protected |
|
921 | + * @return void |
|
922 | + * @throws EE_Error |
|
923 | + * @throws InvalidArgumentException |
|
924 | + * @throws InvalidDataTypeException |
|
925 | + * @throws InvalidInterfaceException |
|
926 | + */ |
|
927 | + protected function _update_payment_settings() |
|
928 | + { |
|
929 | + $form = $this->getPaymentSettingsForm(); |
|
930 | + if ($form->was_submitted($this->_req_data)) { |
|
931 | + $form->receive_form_submission($this->_req_data); |
|
932 | + if ($form->is_valid()) { |
|
933 | + /** |
|
934 | + * @var $reg_config EE_Registration_Config |
|
935 | + */ |
|
936 | + $loader = LoaderFactory::getLoader(); |
|
937 | + $reg_config = $loader->getShared('EE_Registration_Config'); |
|
938 | + $valid_data = $form->valid_data(); |
|
939 | + $reg_config->show_pending_payment_options = $valid_data['show_pending_payment_options']; |
|
940 | + $reg_config->gateway_log_lifespan = $valid_data['gateway_log_lifespan']; |
|
941 | + } |
|
942 | + } |
|
943 | + EE_Registry::instance()->CFG = apply_filters( |
|
944 | + 'FHEE__Payments_Admin_Page___update_payment_settings__CFG', |
|
945 | + EE_Registry::instance()->CFG |
|
946 | + ); |
|
947 | + |
|
948 | + $cfg = EE_Registry::instance()->CFG ; |
|
949 | + |
|
950 | + $what = __('Payment Settings', 'event_espresso'); |
|
951 | + $success = $this->_update_espresso_configuration( |
|
952 | + $what, |
|
953 | + EE_Registry::instance()->CFG, |
|
954 | + __FILE__, |
|
955 | + __FUNCTION__, |
|
956 | + __LINE__ |
|
957 | + ); |
|
958 | + $this->_redirect_after_action( |
|
959 | + $success, |
|
960 | + $what, |
|
961 | + __('updated', 'event_espresso'), |
|
962 | + array('action' => 'payment_settings') |
|
963 | + ); |
|
964 | + } |
|
965 | + |
|
966 | + |
|
967 | + /** |
|
968 | + * Gets the form used for updating payment settings |
|
969 | + * |
|
970 | + * @return EE_Form_Section_Proper |
|
971 | + * @throws EE_Error |
|
972 | + * @throws InvalidArgumentException |
|
973 | + * @throws InvalidDataTypeException |
|
974 | + * @throws InvalidInterfaceException |
|
975 | + */ |
|
976 | + protected function getPaymentSettingsForm() |
|
977 | + { |
|
978 | + /** |
|
979 | + * @var $reg_config EE_Registration_Config |
|
980 | + */ |
|
981 | + $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config'); |
|
982 | + return new EE_Form_Section_Proper( |
|
983 | + array( |
|
984 | + 'name' => 'payment-settings', |
|
985 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
986 | + 'subsections' => array( |
|
987 | + 'show_pending_payment_options' => new EE_Yes_No_Input( |
|
988 | + array( |
|
989 | + 'html_name' => 'show_pending_payment_options', |
|
990 | + 'default' => $reg_config->show_pending_payment_options, |
|
991 | + 'html_help_text' => esc_html__( |
|
992 | + "If a payment is marked as 'Pending Payment', or if payment is deferred (ie, an offline gateway like Check, Bank, or Invoice is used), then give registrants the option to retry payment. ", |
|
993 | + 'event_espresso' |
|
994 | + ) |
|
995 | + ) |
|
996 | + ), |
|
997 | + 'gateway_log_lifespan' => new EE_Select_Input( |
|
998 | + $reg_config->gatewayLogLifespanOptions(), |
|
999 | + array( |
|
1000 | + 'html_label_text' => esc_html__('Gateway Logs Lifespan', 'event_espresso'), |
|
1001 | + 'html_help_text' => esc_html__('If issues arise with payments being made through a payment gateway, it\'s helpful to log non-sensitive communications with the payment gateway. But it\'s a security responsibility, so it\'s a good idea to not keep them for any longer than necessary.', 'event_espresso'), |
|
1002 | + 'default' => $reg_config->gateway_log_lifespan, |
|
1003 | + ) |
|
1004 | + ) |
|
1005 | + ) |
|
1006 | + ) |
|
1007 | + ); |
|
1008 | + } |
|
1009 | + |
|
1010 | + |
|
1011 | + protected function _payment_log_overview_list_table() |
|
1012 | + { |
|
1013 | + $this->display_admin_list_table_page_with_sidebar(); |
|
1014 | + } |
|
1015 | + |
|
1016 | + |
|
1017 | + protected function _set_list_table_views_payment_log() |
|
1018 | + { |
|
1019 | + $this->_views = array( |
|
1020 | + 'all' => array( |
|
1021 | + 'slug' => 'all', |
|
1022 | + 'label' => __('View All Logs', 'event_espresso'), |
|
1023 | + 'count' => 0, |
|
1024 | + ), |
|
1025 | + ); |
|
1026 | + } |
|
1027 | + |
|
1028 | + |
|
1029 | + /** |
|
1030 | + * @param int $per_page |
|
1031 | + * @param int $current_page |
|
1032 | + * @param bool $count |
|
1033 | + * @return array |
|
1034 | + */ |
|
1035 | + public function get_payment_logs($per_page = 50, $current_page = 0, $count = false) |
|
1036 | + { |
|
1037 | + EE_Registry::instance()->load_model('Change_Log'); |
|
1038 | + // we may need to do multiple queries (joining differently), so we actually wan tan array of query params |
|
1039 | + $query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway)); |
|
1040 | + // check if they've selected a specific payment method |
|
1041 | + if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') { |
|
1042 | + $query_params[0]['OR*pm_or_pay_pm'] = array( |
|
1043 | + 'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'], |
|
1044 | + 'Payment_Method.PMD_ID' => $this->_req_data['_payment_method'], |
|
1045 | + ); |
|
1046 | + } |
|
1047 | + // take into account search |
|
1048 | + if (isset($this->_req_data['s']) && $this->_req_data['s']) { |
|
1049 | + $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%'); |
|
1050 | + $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string; |
|
1051 | + $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string; |
|
1052 | + $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string; |
|
1053 | + $query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string; |
|
1054 | + $query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string; |
|
1055 | + $query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string; |
|
1056 | + $query_params[0]['OR*s']['LOG_message'] = $similarity_string; |
|
1057 | + $query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string; |
|
1058 | + $query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string; |
|
1059 | + $query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string; |
|
1060 | + $query_params[0]['OR*s']['LOG_message'] = $similarity_string; |
|
1061 | + } |
|
1062 | + if ( |
|
1063 | + isset($this->_req_data['payment-filter-start-date']) |
|
1064 | + && isset($this->_req_data['payment-filter-end-date']) |
|
1065 | + ) { |
|
1066 | + // add date |
|
1067 | + $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']); |
|
1068 | + $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']); |
|
1069 | + // make sure our timestamps start and end right at the boundaries for each day |
|
1070 | + $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
1071 | + $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
1072 | + // convert to timestamps |
|
1073 | + $start_date = strtotime($start_date); |
|
1074 | + $end_date = strtotime($end_date); |
|
1075 | + // makes sure start date is the lowest value and vice versa |
|
1076 | + $start_date = min($start_date, $end_date); |
|
1077 | + $end_date = max($start_date, $end_date); |
|
1078 | + // convert for query |
|
1079 | + $start_date = EEM_Change_Log::instance() |
|
1080 | + ->convert_datetime_for_query( |
|
1081 | + 'LOG_time', |
|
1082 | + date('Y-m-d H:i:s', $start_date), |
|
1083 | + 'Y-m-d H:i:s' |
|
1084 | + ); |
|
1085 | + $end_date = EEM_Change_Log::instance() |
|
1086 | + ->convert_datetime_for_query( |
|
1087 | + 'LOG_time', |
|
1088 | + date('Y-m-d H:i:s', $end_date), |
|
1089 | + 'Y-m-d H:i:s' |
|
1090 | + ); |
|
1091 | + $query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date)); |
|
1092 | + } |
|
1093 | + if ($count) { |
|
1094 | + return EEM_Change_Log::instance()->count($query_params); |
|
1095 | + } |
|
1096 | + if (isset($this->_req_data['order'])) { |
|
1097 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
1098 | + : 'DESC'; |
|
1099 | + $query_params['order_by'] = array('LOG_time' => $sort); |
|
1100 | + } else { |
|
1101 | + $query_params['order_by'] = array('LOG_time' => 'DESC'); |
|
1102 | + } |
|
1103 | + $offset = ($current_page - 1) * $per_page; |
|
1104 | + if (! isset($this->_req_data['download_results'])) { |
|
1105 | + $query_params['limit'] = array($offset, $per_page); |
|
1106 | + } |
|
1107 | + // now they've requested to instead just download the file instead of viewing it. |
|
1108 | + if (isset($this->_req_data['download_results'])) { |
|
1109 | + $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params); |
|
1110 | + header('Content-Disposition: attachment'); |
|
1111 | + header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url())); |
|
1112 | + echo "<h1>Payment Logs for " . site_url() . "</h1>"; |
|
1113 | + echo "<h3>Query:</h3>"; |
|
1114 | + var_dump($query_params); |
|
1115 | + echo "<h3>Results:</h3>"; |
|
1116 | + var_dump($wpdb_results); |
|
1117 | + die; |
|
1118 | + } |
|
1119 | + $results = EEM_Change_Log::instance()->get_all($query_params); |
|
1120 | + return $results; |
|
1121 | + } |
|
1122 | + |
|
1123 | + |
|
1124 | + /** |
|
1125 | + * Used by usort to RE-sort log query results, because we lose the ordering |
|
1126 | + * because we're possibly combining the results from two queries |
|
1127 | + * |
|
1128 | + * @param EE_Change_Log $logA |
|
1129 | + * @param EE_Change_Log $logB |
|
1130 | + * @return int |
|
1131 | + */ |
|
1132 | + protected function _sort_logs_again($logA, $logB) |
|
1133 | + { |
|
1134 | + $timeA = $logA->get_raw('LOG_time'); |
|
1135 | + $timeB = $logB->get_raw('LOG_time'); |
|
1136 | + if ($timeA == $timeB) { |
|
1137 | + return 0; |
|
1138 | + } |
|
1139 | + $comparison = $timeA < $timeB ? -1 : 1; |
|
1140 | + if (strtoupper($this->_sort_logs_again_direction) == 'DESC') { |
|
1141 | + return $comparison * -1; |
|
1142 | + } else { |
|
1143 | + return $comparison; |
|
1144 | + } |
|
1145 | + } |
|
1146 | + |
|
1147 | + |
|
1148 | + protected function _payment_log_details() |
|
1149 | + { |
|
1150 | + EE_Registry::instance()->load_model('Change_Log'); |
|
1151 | + /** @var $payment_log EE_Change_Log */ |
|
1152 | + $payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']); |
|
1153 | + $payment_method = null; |
|
1154 | + $transaction = null; |
|
1155 | + if ($payment_log instanceof EE_Change_Log) { |
|
1156 | + if ($payment_log->object() instanceof EE_Payment) { |
|
1157 | + $payment_method = $payment_log->object()->payment_method(); |
|
1158 | + $transaction = $payment_log->object()->transaction(); |
|
1159 | + } elseif ($payment_log->object() instanceof EE_Payment_Method) { |
|
1160 | + $payment_method = $payment_log->object(); |
|
1161 | + } elseif ($payment_log->object() instanceof EE_Transaction) { |
|
1162 | + $transaction = $payment_log->object(); |
|
1163 | + $payment_method = $transaction->payment_method(); |
|
1164 | + } |
|
1165 | + } |
|
1166 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
1167 | + EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php', |
|
1168 | + array( |
|
1169 | + 'payment_log' => $payment_log, |
|
1170 | + 'payment_method' => $payment_method, |
|
1171 | + 'transaction' => $transaction, |
|
1172 | + ), |
|
1173 | + true |
|
1174 | + ); |
|
1175 | + $this->display_admin_page_with_no_sidebar(); |
|
1176 | + } |
|
1177 | 1177 | } |
@@ -194,10 +194,10 @@ discard block |
||
194 | 194 | foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) { |
195 | 195 | $template_args = isset($config['template_args']) ? $config['template_args'] : array(); |
196 | 196 | $template_args['admin_page_obj'] = $this; |
197 | - $all_pmt_help_tabs_config[ $help_tab_name ] = array( |
|
197 | + $all_pmt_help_tabs_config[$help_tab_name] = array( |
|
198 | 198 | 'title' => $config['title'], |
199 | 199 | 'content' => EEH_Template::display_template( |
200 | - $payment_method_type->file_folder() . 'help_tabs/' . $config['filename'] . '.help_tab.php', |
|
200 | + $payment_method_type->file_folder().'help_tabs/'.$config['filename'].'.help_tab.php', |
|
201 | 201 | $template_args, |
202 | 202 | true |
203 | 203 | ), |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | wp_enqueue_style('espresso-ui-theme'); |
241 | 241 | wp_register_style( |
242 | 242 | 'espresso_payments', |
243 | - EE_PAYMENTS_ASSETS_URL . 'ee-payments.css', |
|
243 | + EE_PAYMENTS_ASSETS_URL.'ee-payments.css', |
|
244 | 244 | [], |
245 | 245 | EVENT_ESPRESSO_VERSION |
246 | 246 | ); |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | wp_enqueue_script('ee-text-links'); |
250 | 250 | wp_enqueue_script( |
251 | 251 | 'espresso_payments', |
252 | - EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js', |
|
252 | + EE_PAYMENTS_ASSETS_URL.'espresso_payments_admin.js', |
|
253 | 253 | ['ee-datepicker'], |
254 | 254 | EVENT_ESPRESSO_VERSION, |
255 | 255 | true |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | } |
300 | 300 | // check for any active pms of that type |
301 | 301 | $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name()); |
302 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
302 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
303 | 303 | $payment_method = EE_Payment_Method::new_instance( |
304 | 304 | array( |
305 | 305 | 'PMD_slug' => sanitize_key($pmt_obj->system_name()), |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | ) |
310 | 310 | ); |
311 | 311 | } |
312 | - $payment_methods[ $payment_method->slug() ] = $payment_method; |
|
312 | + $payment_methods[$payment_method->slug()] = $payment_method; |
|
313 | 313 | } |
314 | 314 | $payment_methods = apply_filters( |
315 | 315 | 'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | if ($payment_method instanceof EE_Payment_Method) { |
320 | 320 | add_meta_box( |
321 | 321 | // html id |
322 | - 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
322 | + 'espresso_'.$payment_method->slug().'_payment_settings', |
|
323 | 323 | // title |
324 | 324 | sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()), |
325 | 325 | // callback |
@@ -334,10 +334,10 @@ discard block |
||
334 | 334 | array('payment_method' => $payment_method) |
335 | 335 | ); |
336 | 336 | // setup for tabbed content |
337 | - $tabs[ $payment_method->slug() ] = array( |
|
337 | + $tabs[$payment_method->slug()] = array( |
|
338 | 338 | 'label' => $payment_method->admin_name(), |
339 | 339 | 'class' => $payment_method->active() ? 'gateway-active' : '', |
340 | - 'href' => 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
340 | + 'href' => 'espresso_'.$payment_method->slug().'_payment_settings', |
|
341 | 341 | 'title' => __('Modify this Payment Method', 'event_espresso'), |
342 | 342 | 'slug' => $payment_method->slug(), |
343 | 343 | ); |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | } |
369 | 369 | $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug))); |
370 | 370 | // if that didn't work or wasn't provided, find another way to select the current pm |
371 | - if (! $this->_verify_payment_method($payment_method)) { |
|
371 | + if ( ! $this->_verify_payment_method($payment_method)) { |
|
372 | 372 | // like, looking for an active one |
373 | 373 | $payment_method = EEM_Payment_Method::instance()->get_one_active('CART'); |
374 | 374 | // test that one as well |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | { |
419 | 419 | $payment_method = isset($metabox['args'], $metabox['args']['payment_method']) |
420 | 420 | ? $metabox['args']['payment_method'] : null; |
421 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
421 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
422 | 422 | throw new EE_Error( |
423 | 423 | sprintf( |
424 | 424 | __( |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | if ($form->form_data_present_in($this->_req_data)) { |
436 | 436 | $form->receive_form_submission($this->_req_data); |
437 | 437 | } |
438 | - echo $form->form_open() . $form->get_html_and_js() . $form->form_close(); |
|
438 | + echo $form->form_open().$form->get_html_and_js().$form->form_close(); |
|
439 | 439 | } else { |
440 | 440 | echo $this->_activate_payment_method_button($payment_method)->get_html_and_js(); |
441 | 441 | } |
@@ -451,13 +451,13 @@ discard block |
||
451 | 451 | */ |
452 | 452 | protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method) |
453 | 453 | { |
454 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
454 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
455 | 455 | return new EE_Form_Section_Proper(); |
456 | 456 | } |
457 | 457 | return new EE_Form_Section_Proper( |
458 | 458 | array( |
459 | - 'name' => $payment_method->slug() . '_settings_form', |
|
460 | - 'html_id' => $payment_method->slug() . '_settings_form', |
|
459 | + 'name' => $payment_method->slug().'_settings_form', |
|
460 | + 'html_id' => $payment_method->slug().'_settings_form', |
|
461 | 461 | 'action' => EE_Admin_Page::add_query_args_and_nonce( |
462 | 462 | array( |
463 | 463 | 'action' => 'update_payment_method', |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | EEH_HTML::label( |
501 | 501 | EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
502 | 502 | ) |
503 | - ) . |
|
503 | + ). |
|
504 | 504 | EEH_HTML::td( |
505 | 505 | EEH_HTML::strong( |
506 | 506 | __( |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | */ |
536 | 536 | protected function _currency_support(EE_Payment_Method $payment_method) |
537 | 537 | { |
538 | - if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) { |
|
538 | + if ( ! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) { |
|
539 | 539 | return new EE_Form_Section_HTML( |
540 | 540 | EEH_HTML::table( |
541 | 541 | EEH_HTML::tr( |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | EEH_HTML::label( |
544 | 544 | EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
545 | 545 | ) |
546 | - ) . |
|
546 | + ). |
|
547 | 547 | EEH_HTML::td( |
548 | 548 | EEH_HTML::strong( |
549 | 549 | sprintf( |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | $update_button = new EE_Submit_Input( |
625 | 625 | array( |
626 | 626 | 'name' => 'submit', |
627 | - 'html_id' => 'save_' . $payment_method->slug() . '_settings', |
|
627 | + 'html_id' => 'save_'.$payment_method->slug().'_settings', |
|
628 | 628 | 'default' => sprintf( |
629 | 629 | __('Update %s Payment Settings', 'event_espresso'), |
630 | 630 | $payment_method->admin_name() |
@@ -634,9 +634,9 @@ discard block |
||
634 | 634 | ); |
635 | 635 | return new EE_Form_Section_HTML( |
636 | 636 | EEH_HTML::table( |
637 | - EEH_HTML::no_row(EEH_HTML::br(2)) . |
|
637 | + EEH_HTML::no_row(EEH_HTML::br(2)). |
|
638 | 638 | EEH_HTML::tr( |
639 | - EEH_HTML::th(__('Update Settings', 'event_espresso')) . |
|
639 | + EEH_HTML::th(__('Update Settings', 'event_espresso')). |
|
640 | 640 | EEH_HTML::td( |
641 | 641 | $update_button->get_html_for_input() |
642 | 642 | ) |
@@ -662,7 +662,7 @@ discard block |
||
662 | 662 | return new EE_Form_Section_HTML( |
663 | 663 | EEH_HTML::table( |
664 | 664 | EEH_HTML::tr( |
665 | - EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) . |
|
665 | + EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')). |
|
666 | 666 | EEH_HTML::td( |
667 | 667 | EEH_HTML::link( |
668 | 668 | EE_Admin_Page::add_query_args_and_nonce( |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | ), |
675 | 675 | $link_text_and_title, |
676 | 676 | $link_text_and_title, |
677 | - 'deactivate_' . $payment_method->slug(), |
|
677 | + 'deactivate_'.$payment_method->slug(), |
|
678 | 678 | 'espresso-button button-secondary' |
679 | 679 | ) |
680 | 680 | ) |
@@ -699,8 +699,8 @@ discard block |
||
699 | 699 | ); |
700 | 700 | return new EE_Form_Section_Proper( |
701 | 701 | array( |
702 | - 'name' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
703 | - 'html_id' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
702 | + 'name' => 'activate_'.$payment_method->slug().'_settings_form', |
|
703 | + 'html_id' => 'activate_'.$payment_method->slug().'_settings_form', |
|
704 | 704 | 'action' => '#', |
705 | 705 | 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
706 | 706 | 'subsections' => apply_filters( |
@@ -716,11 +716,11 @@ discard block |
||
716 | 716 | '', |
717 | 717 | 'colspan="2"' |
718 | 718 | ) |
719 | - ) . |
|
719 | + ). |
|
720 | 720 | EEH_HTML::tr( |
721 | 721 | EEH_HTML::th( |
722 | 722 | EEH_HTML::label(__('Click to Activate ', 'event_espresso')) |
723 | - ) . |
|
723 | + ). |
|
724 | 724 | EEH_HTML::td( |
725 | 725 | EEH_HTML::link( |
726 | 726 | EE_Admin_Page::add_query_args_and_nonce( |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | ), |
733 | 733 | $link_text_and_title, |
734 | 734 | $link_text_and_title, |
735 | - 'activate_' . $payment_method->slug(), |
|
735 | + 'activate_'.$payment_method->slug(), |
|
736 | 736 | 'espresso-button-green button-primary' |
737 | 737 | ) |
738 | 738 | ) |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | return new EE_Form_Section_HTML( |
759 | 759 | EEH_HTML::table( |
760 | 760 | EEH_HTML::tr( |
761 | - EEH_HTML::th() . |
|
761 | + EEH_HTML::th(). |
|
762 | 762 | EEH_HTML::td( |
763 | 763 | EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text') |
764 | 764 | ) |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | } |
843 | 843 | } |
844 | 844 | // if we couldn't find the correct payment method type... |
845 | - if (! $correct_pmt_form_to_use) { |
|
845 | + if ( ! $correct_pmt_form_to_use) { |
|
846 | 846 | EE_Error::add_error( |
847 | 847 | __( |
848 | 848 | "We could not find which payment method type your form submission related to. Please contact support", |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | $correct_pmt_form_to_use->receive_form_submission($this->_req_data); |
858 | 858 | if ($correct_pmt_form_to_use->is_valid()) { |
859 | 859 | $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings'); |
860 | - if (! $payment_settings_subform instanceof EE_Payment_Method_Form) { |
|
860 | + if ( ! $payment_settings_subform instanceof EE_Payment_Method_Form) { |
|
861 | 861 | throw new EE_Error( |
862 | 862 | sprintf( |
863 | 863 | __( |
@@ -909,7 +909,7 @@ discard block |
||
909 | 909 | $form = $this->getPaymentSettingsForm(); |
910 | 910 | $this->_set_add_edit_form_tags('update_payment_settings'); |
911 | 911 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
912 | - $this->_template_args['admin_page_content'] = $form->get_html_and_js(); |
|
912 | + $this->_template_args['admin_page_content'] = $form->get_html_and_js(); |
|
913 | 913 | $this->display_admin_page_with_sidebar(); |
914 | 914 | } |
915 | 915 | |
@@ -945,7 +945,7 @@ discard block |
||
945 | 945 | EE_Registry::instance()->CFG |
946 | 946 | ); |
947 | 947 | |
948 | - $cfg = EE_Registry::instance()->CFG ; |
|
948 | + $cfg = EE_Registry::instance()->CFG; |
|
949 | 949 | |
950 | 950 | $what = __('Payment Settings', 'event_espresso'); |
951 | 951 | $success = $this->_update_espresso_configuration( |
@@ -1046,7 +1046,7 @@ discard block |
||
1046 | 1046 | } |
1047 | 1047 | // take into account search |
1048 | 1048 | if (isset($this->_req_data['s']) && $this->_req_data['s']) { |
1049 | - $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%'); |
|
1049 | + $similarity_string = array('LIKE', '%'.str_replace("", "%", $this->_req_data['s']).'%'); |
|
1050 | 1050 | $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string; |
1051 | 1051 | $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string; |
1052 | 1052 | $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string; |
@@ -1067,8 +1067,8 @@ discard block |
||
1067 | 1067 | $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']); |
1068 | 1068 | $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']); |
1069 | 1069 | // make sure our timestamps start and end right at the boundaries for each day |
1070 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
1071 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
1070 | + $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00'; |
|
1071 | + $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59'; |
|
1072 | 1072 | // convert to timestamps |
1073 | 1073 | $start_date = strtotime($start_date); |
1074 | 1074 | $end_date = strtotime($end_date); |
@@ -1101,15 +1101,15 @@ discard block |
||
1101 | 1101 | $query_params['order_by'] = array('LOG_time' => 'DESC'); |
1102 | 1102 | } |
1103 | 1103 | $offset = ($current_page - 1) * $per_page; |
1104 | - if (! isset($this->_req_data['download_results'])) { |
|
1104 | + if ( ! isset($this->_req_data['download_results'])) { |
|
1105 | 1105 | $query_params['limit'] = array($offset, $per_page); |
1106 | 1106 | } |
1107 | 1107 | // now they've requested to instead just download the file instead of viewing it. |
1108 | 1108 | if (isset($this->_req_data['download_results'])) { |
1109 | 1109 | $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params); |
1110 | 1110 | header('Content-Disposition: attachment'); |
1111 | - header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url())); |
|
1112 | - echo "<h1>Payment Logs for " . site_url() . "</h1>"; |
|
1111 | + header("Content-Disposition: attachment; filename=ee_payment_logs_for_".sanitize_key(site_url())); |
|
1112 | + echo "<h1>Payment Logs for ".site_url()."</h1>"; |
|
1113 | 1113 | echo "<h3>Query:</h3>"; |
1114 | 1114 | var_dump($query_params); |
1115 | 1115 | echo "<h3>Results:</h3>"; |
@@ -1164,7 +1164,7 @@ discard block |
||
1164 | 1164 | } |
1165 | 1165 | } |
1166 | 1166 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
1167 | - EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php', |
|
1167 | + EE_PAYMENTS_TEMPLATE_PATH.'payment_log_details.template.php', |
|
1168 | 1168 | array( |
1169 | 1169 | 'payment_log' => $payment_log, |
1170 | 1170 | 'payment_method' => $payment_method, |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | </th> |
34 | 34 | <td> |
35 | 35 | <?php |
36 | - if ($payment_log->object() instanceof EE_Transaction) { |
|
37 | - esc_html_e('Unknown', 'event_espresso'); |
|
38 | - } else { |
|
39 | - echo $payment_method |
|
40 | - ? $payment_method->admin_name() |
|
41 | - : esc_html__( |
|
42 | - "No Longer Exists", |
|
43 | - 'event_espresso' |
|
44 | - ); |
|
45 | - } |
|
46 | - ?> |
|
36 | + if ($payment_log->object() instanceof EE_Transaction) { |
|
37 | + esc_html_e('Unknown', 'event_espresso'); |
|
38 | + } else { |
|
39 | + echo $payment_method |
|
40 | + ? $payment_method->admin_name() |
|
41 | + : esc_html__( |
|
42 | + "No Longer Exists", |
|
43 | + 'event_espresso' |
|
44 | + ); |
|
45 | + } |
|
46 | + ?> |
|
47 | 47 | |
48 | 48 | </td> |
49 | 49 | </tr> |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | </th> |
67 | 67 | <td class='ee-payment-log-details__content'> |
68 | 68 | <?php |
69 | - echo $payment_log->e('LOG_message', 'as_table'); |
|
70 | - // EEH_Template::layout_array_as_table($payment_log->content()) |
|
71 | - ?> |
|
69 | + echo $payment_log->e('LOG_message', 'as_table'); |
|
70 | + // EEH_Template::layout_array_as_table($payment_log->content()) |
|
71 | + ?> |
|
72 | 72 | </td> |
73 | 73 | </tr> |
74 | 74 | </tbody> |