Completed
Branch BUG/fix-espresso-payment-dep (a762bb)
by
unknown
09:51 queued 37s
created
admin_pages/payments/Payments_Admin_Page.core.php 2 patches
Indentation   +1149 added lines, -1149 removed lines patch added patch discarded remove patch
@@ -16,1153 +16,1153 @@
 block discarded – undo
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
-            'help_tour'     => array('Payment_Methods_Selection_Help_Tour'),
138
-            'require_nonce' => false,
139
-        );
140
-        $this->_page_config = array(
141
-            'default'          => $payment_method_list_config,
142
-            'payment_settings' => array(
143
-                'nav'           => array(
144
-                    'label' => __('Settings', 'event_espresso'),
145
-                    'order' => 20,
146
-                ),
147
-                'help_tabs'     => array(
148
-                    'payment_methods_settings_help_tab' => array(
149
-                        'title'    => __('Payment Method Settings', 'event_espresso'),
150
-                        'filename' => 'payment_methods_settings',
151
-                    ),
152
-                ),
153
-                // 'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ),
154
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
155
-                'require_nonce' => false,
156
-            ),
157
-            'payment_log'      => array(
158
-                'nav'           => array(
159
-                    'label' => __("Logs", 'event_espresso'),
160
-                    'order' => 30,
161
-                ),
162
-                'list_table'    => 'Payment_Log_Admin_List_Table',
163
-                'metaboxes'     => $this->_default_espresso_metaboxes,
164
-                'require_nonce' => false,
165
-            ),
166
-        );
167
-    }
168
-
169
-
170
-    /**
171
-     * @return array
172
-     * @throws DomainException
173
-     * @throws EE_Error
174
-     * @throws InvalidArgumentException
175
-     * @throws InvalidDataTypeException
176
-     * @throws InvalidInterfaceException
177
-     * @throws ReflectionException
178
-     */
179
-    protected function _add_payment_method_help_tabs()
180
-    {
181
-        EE_Registry::instance()->load_lib('Payment_Method_Manager');
182
-        $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types();
183
-        $all_pmt_help_tabs_config = array();
184
-        foreach ($payment_method_types as $payment_method_type) {
185
-            if (! EE_Registry::instance()->CAP->current_user_can(
186
-                $payment_method_type->cap_name(),
187
-                'specific_payment_method_type_access'
188
-            )
189
-            ) {
190
-                continue;
191
-            }
192
-            foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
193
-                $template_args = isset($config['template_args']) ? $config['template_args'] : array();
194
-                $template_args['admin_page_obj'] = $this;
195
-                $all_pmt_help_tabs_config[ $help_tab_name ] = array(
196
-                    'title'   => $config['title'],
197
-                    'content' => EEH_Template::display_template(
198
-                        $payment_method_type->file_folder() . 'help_tabs/' . $config['filename'] . '.help_tab.php',
199
-                        $template_args,
200
-                        true
201
-                    ),
202
-                );
203
-            }
204
-        }
205
-        return $all_pmt_help_tabs_config;
206
-    }
207
-
208
-
209
-    // none of the below group are currently used for Gateway Settings
210
-    protected function _add_screen_options()
211
-    {
212
-    }
213
-
214
-
215
-    protected function _add_feature_pointers()
216
-    {
217
-    }
218
-
219
-
220
-    public function admin_init()
221
-    {
222
-    }
223
-
224
-
225
-    public function admin_notices()
226
-    {
227
-    }
228
-
229
-
230
-    public function admin_footer_scripts()
231
-    {
232
-    }
233
-
234
-
235
-    public function load_scripts_styles()
236
-    {
237
-        // styles
238
-        wp_enqueue_style('espresso-ui-theme');
239
-        // scripts
240
-        wp_enqueue_script('ee_admin_js');
241
-        wp_enqueue_script('ee-text-links');
242
-        wp_enqueue_script(
243
-            'espresso_payments',
244
-            EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
245
-            array('ee-datepicker'),
246
-            EVENT_ESPRESSO_VERSION,
247
-            true
248
-        );
249
-    }
250
-
251
-
252
-    public function load_scripts_styles_default()
253
-    {
254
-        // styles
255
-        wp_register_style(
256
-            'espresso_payments',
257
-            EE_PAYMENTS_ASSETS_URL . 'ee-payments.css',
258
-            array(),
259
-            EVENT_ESPRESSO_VERSION
260
-        );
261
-        wp_enqueue_style('espresso_payments');
262
-        wp_enqueue_style('ee-text-links');
263
-        // scripts
264
-    }
265
-
266
-
267
-    protected function _payment_methods_list()
268
-    {
269
-        /**
270
-         * first let's ensure payment methods have been setup. We do this here because when people activate a
271
-         * payment method for the first time (as an addon), it may not setup its capabilities or get registered
272
-         * correctly due to the loading process.  However, people MUST setup the details for the payment method so its
273
-         * safe to do a recheck here.
274
-         */
275
-        EE_Registry::instance()->load_lib('Payment_Method_Manager');
276
-        EEM_Payment_Method::instance()->verify_button_urls();
277
-        // setup tabs, one for each payment method type
278
-        $tabs = array();
279
-        $payment_methods = array();
280
-        foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) {
281
-            // we don't want to show admin-only PMTs for now
282
-            if ($pmt_obj instanceof EE_PMT_Admin_Only) {
283
-                continue;
284
-            }
285
-            // check access
286
-            if (! EE_Registry::instance()->CAP->current_user_can(
287
-                $pmt_obj->cap_name(),
288
-                'specific_payment_method_type_access'
289
-            )
290
-            ) {
291
-                continue;
292
-            }
293
-            // check for any active pms of that type
294
-            $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
295
-            if (! $payment_method instanceof EE_Payment_Method) {
296
-                $payment_method = EE_Payment_Method::new_instance(
297
-                    array(
298
-                        'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
299
-                        'PMD_type'       => $pmt_obj->system_name(),
300
-                        'PMD_name'       => $pmt_obj->pretty_name(),
301
-                        'PMD_admin_name' => $pmt_obj->pretty_name(),
302
-                    )
303
-                );
304
-            }
305
-            $payment_methods[ $payment_method->slug() ] = $payment_method;
306
-        }
307
-        $payment_methods = apply_filters(
308
-            'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
309
-            $payment_methods
310
-        );
311
-        foreach ($payment_methods as $payment_method) {
312
-            if ($payment_method instanceof EE_Payment_Method) {
313
-                add_meta_box(
314
-                    // html id
315
-                    'espresso_' . $payment_method->slug() . '_payment_settings',
316
-                    // title
317
-                    sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
318
-                    // callback
319
-                    array($this, 'payment_method_settings_meta_box'),
320
-                    // post type
321
-                    null,
322
-                    // context
323
-                    'normal',
324
-                    // priority
325
-                    'default',
326
-                    // callback args
327
-                    array('payment_method' => $payment_method)
328
-                );
329
-                // setup for tabbed content
330
-                $tabs[ $payment_method->slug() ] = array(
331
-                    'label' => $payment_method->admin_name(),
332
-                    'class' => $payment_method->active() ? 'gateway-active' : '',
333
-                    'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
334
-                    'title' => __('Modify this Payment Method', 'event_espresso'),
335
-                    'slug'  => $payment_method->slug(),
336
-                );
337
-            }
338
-        }
339
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
340
-            $tabs,
341
-            'payment_method_links',
342
-            '|',
343
-            $this->_get_active_payment_method_slug()
344
-        );
345
-        $this->display_admin_page_with_sidebar();
346
-    }
347
-
348
-
349
-    /**
350
-     *   _get_active_payment_method_slug
351
-     *
352
-     * @return string
353
-     */
354
-    protected function _get_active_payment_method_slug()
355
-    {
356
-        $payment_method_slug = false;
357
-        // decide which payment method tab to open first, as dictated by the request's 'payment_method'
358
-        if (isset($this->_req_data['payment_method'])) {
359
-            // if they provided the current payment method, use it
360
-            $payment_method_slug = sanitize_key($this->_req_data['payment_method']);
361
-        }
362
-        $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
363
-        // if that didn't work or wasn't provided, find another way to select the current pm
364
-        if (! $this->_verify_payment_method($payment_method)) {
365
-            // like, looking for an active one
366
-            $payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
367
-            // test that one as well
368
-            if ($this->_verify_payment_method($payment_method)) {
369
-                $payment_method_slug = $payment_method->slug();
370
-            } else {
371
-                $payment_method_slug = 'paypal_standard';
372
-            }
373
-        }
374
-        return $payment_method_slug;
375
-    }
376
-
377
-
378
-    /**
379
-     *    payment_method_settings_meta_box
380
-     *    returns TRUE if the passed payment method is properly constructed and the logged in user has the correct
381
-     *    capabilities to access it
382
-     *
383
-     * @param EE_Payment_Method $payment_method
384
-     * @return boolean
385
-     */
386
-    protected function _verify_payment_method($payment_method)
387
-    {
388
-        if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base
389
-            && EE_Registry::instance()->CAP->current_user_can(
390
-                $payment_method->type_obj()->cap_name(),
391
-                'specific_payment_method_type_access'
392
-            )
393
-        ) {
394
-            return true;
395
-        }
396
-        return false;
397
-    }
398
-
399
-
400
-    /**
401
-     *    payment_method_settings_meta_box
402
-     *
403
-     * @param NULL  $post_obj_which_is_null is an object containing the current post (as a $post object)
404
-     * @param array $metabox                is an array with metabox id, title, callback, and args elements. the value
405
-     *                                      at 'args' has key 'payment_method', as set within _payment_methods_list
406
-     * @return string
407
-     * @throws EE_Error
408
-     */
409
-    public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox)
410
-    {
411
-        $payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
412
-            ? $metabox['args']['payment_method'] : null;
413
-        if (! $payment_method instanceof EE_Payment_Method) {
414
-            throw new EE_Error(
415
-                sprintf(
416
-                    __(
417
-                        'Payment method metabox setup incorrectly. No Payment method object was supplied',
418
-                        'event_espresso'
419
-                    )
420
-                )
421
-            );
422
-        }
423
-        $payment_method_scopes = $payment_method->active();
424
-        // if the payment method really exists show its form, otherwise the activation template
425
-        if ($payment_method->ID() && ! empty($payment_method_scopes)) {
426
-            $form = $this->_generate_payment_method_settings_form($payment_method);
427
-            if ($form->form_data_present_in($this->_req_data)) {
428
-                $form->receive_form_submission($this->_req_data);
429
-            }
430
-            echo $form->form_open() . $form->get_html_and_js() . $form->form_close();
431
-        } else {
432
-            echo $this->_activate_payment_method_button($payment_method)->get_html_and_js();
433
-        }
434
-    }
435
-
436
-
437
-    /**
438
-     * Gets the form for all the settings related to this payment method type
439
-     *
440
-     * @access protected
441
-     * @param EE_Payment_Method $payment_method
442
-     * @return EE_Form_Section_Proper
443
-     */
444
-    protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method)
445
-    {
446
-        if (! $payment_method instanceof EE_Payment_Method) {
447
-            return new EE_Form_Section_Proper();
448
-        }
449
-        return new EE_Form_Section_Proper(
450
-            array(
451
-                'name'            => $payment_method->slug() . '_settings_form',
452
-                'html_id'         => $payment_method->slug() . '_settings_form',
453
-                'action'          => EE_Admin_Page::add_query_args_and_nonce(
454
-                    array(
455
-                        'action'         => 'update_payment_method',
456
-                        'payment_method' => $payment_method->slug(),
457
-                    ),
458
-                    EE_PAYMENTS_ADMIN_URL
459
-                ),
460
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
461
-                'subsections'     => apply_filters(
462
-                    'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections',
463
-                    array(
464
-                        'pci_dss_compliance'      => $this->_pci_dss_compliance($payment_method),
465
-                        'currency_support'        => $this->_currency_support($payment_method),
466
-                        'payment_method_settings' => $this->_payment_method_settings($payment_method),
467
-                        'update'                  => $this->_update_payment_method_button($payment_method),
468
-                        'deactivate'              => $this->_deactivate_payment_method_button($payment_method),
469
-                        'fine_print'              => $this->_fine_print(),
470
-                    ),
471
-                    $payment_method
472
-                ),
473
-            )
474
-        );
475
-    }
476
-
477
-
478
-    /**
479
-     * _pci_dss_compliance
480
-     *
481
-     * @access protected
482
-     * @param EE_Payment_Method $payment_method
483
-     * @return EE_Form_Section_Proper
484
-     */
485
-    protected function _pci_dss_compliance(EE_Payment_Method $payment_method)
486
-    {
487
-        if ($payment_method->type_obj()->requires_https()) {
488
-            return new EE_Form_Section_HTML(
489
-                EEH_HTML::table(
490
-                    EEH_HTML::tr(
491
-                        EEH_HTML::th(
492
-                            EEH_HTML::label(
493
-                                EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
494
-                            )
495
-                        ) .
496
-                        EEH_HTML::td(
497
-                            EEH_HTML::strong(
498
-                                __(
499
-                                    'You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.',
500
-                                    'event_espresso'
501
-                                )
502
-                            )
503
-                            .
504
-                            EEH_HTML::br()
505
-                            .
506
-                            __('Learn more about ', 'event_espresso')
507
-                            . EEH_HTML::link(
508
-                                'https://www.pcisecuritystandards.org/merchants/index.php',
509
-                                __('PCI DSS compliance', 'event_espresso')
510
-                            )
511
-                        )
512
-                    )
513
-                )
514
-            );
515
-        } else {
516
-            return new EE_Form_Section_HTML('');
517
-        }
518
-    }
519
-
520
-
521
-    /**
522
-     * _currency_support
523
-     *
524
-     * @access protected
525
-     * @param EE_Payment_Method $payment_method
526
-     * @return EE_Form_Section_Proper
527
-     */
528
-    protected function _currency_support(EE_Payment_Method $payment_method)
529
-    {
530
-        if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
531
-            return new EE_Form_Section_HTML(
532
-                EEH_HTML::table(
533
-                    EEH_HTML::tr(
534
-                        EEH_HTML::th(
535
-                            EEH_HTML::label(
536
-                                EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
537
-                            )
538
-                        ) .
539
-                        EEH_HTML::td(
540
-                            EEH_HTML::strong(
541
-                                sprintf(
542
-                                    __(
543
-                                        '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.',
544
-                                        'event_espresso'
545
-                                    ),
546
-                                    EE_Config::instance()->currency->code
547
-                                )
548
-                            )
549
-                        )
550
-                    )
551
-                )
552
-            );
553
-        } else {
554
-            return new EE_Form_Section_HTML('');
555
-        }
556
-    }
557
-
558
-
559
-    /**
560
-     * _update_payment_method_button
561
-     *
562
-     * @access protected
563
-     * @param EE_Payment_Method $payment_method
564
-     * @return EE_Payment_Method_Form
565
-     */
566
-    protected function _payment_method_settings(EE_Payment_Method $payment_method)
567
-    {
568
-        // modify the form so we only have/show fields that will be implemented for this version
569
-        return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name());
570
-    }
571
-
572
-
573
-    /**
574
-     * Simplifies the form to merely reproduce 4.1's gateway settings functionality
575
-     *
576
-     * @param EE_Form_Section_Proper $form_section
577
-     * @param string                 $payment_method_name
578
-     * @return EE_Payment_Method_Form
579
-     * @throws EE_Error
580
-     */
581
-    protected function _simplify_form($form_section, $payment_method_name = '')
582
-    {
583
-        if ($form_section instanceof EE_Payment_Method_Form) {
584
-            $form_section->exclude(
585
-                array(
586
-                    'PMD_type', // dont want them changing the type
587
-                    'PMD_slug', // or the slug (probably never)
588
-                    'PMD_wp_user', // or the user's ID
589
-                    'Currency' // or the currency, until the rest of EE supports simultaneous currencies
590
-                )
591
-            );
592
-            return $form_section;
593
-        } else {
594
-            throw new EE_Error(
595
-                sprintf(
596
-                    __(
597
-                        'The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.',
598
-                        'event_espresso'
599
-                    ),
600
-                    $payment_method_name
601
-                )
602
-            );
603
-        }
604
-    }
605
-
606
-
607
-    /**
608
-     * _update_payment_method_button
609
-     *
610
-     * @access protected
611
-     * @param EE_Payment_Method $payment_method
612
-     * @return EE_Form_Section_HTML
613
-     */
614
-    protected function _update_payment_method_button(EE_Payment_Method $payment_method)
615
-    {
616
-        $update_button = new EE_Submit_Input(
617
-            array(
618
-                'name'       => 'submit',
619
-                'html_id'    => 'save_' . $payment_method->slug() . '_settings',
620
-                'default'    => sprintf(
621
-                    __('Update %s Payment Settings', 'event_espresso'),
622
-                    $payment_method->admin_name()
623
-                ),
624
-                'html_label' => EEH_HTML::nbsp(),
625
-            )
626
-        );
627
-        return new EE_Form_Section_HTML(
628
-            EEH_HTML::table(
629
-                EEH_HTML::no_row(EEH_HTML::br(2)) .
630
-                EEH_HTML::tr(
631
-                    EEH_HTML::th(__('Update Settings', 'event_espresso')) .
632
-                    EEH_HTML::td(
633
-                        $update_button->get_html_for_input()
634
-                    )
635
-                )
636
-            )
637
-        );
638
-    }
639
-
640
-
641
-    /**
642
-     * _deactivate_payment_method_button
643
-     *
644
-     * @access protected
645
-     * @param EE_Payment_Method $payment_method
646
-     * @return EE_Form_Section_Proper
647
-     */
648
-    protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method)
649
-    {
650
-        $link_text_and_title = sprintf(
651
-            __('Deactivate %1$s Payments?', 'event_espresso'),
652
-            $payment_method->admin_name()
653
-        );
654
-        return new EE_Form_Section_HTML(
655
-            EEH_HTML::table(
656
-                EEH_HTML::tr(
657
-                    EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) .
658
-                    EEH_HTML::td(
659
-                        EEH_HTML::link(
660
-                            EE_Admin_Page::add_query_args_and_nonce(
661
-                                array(
662
-                                    'action'         => 'deactivate_payment_method',
663
-                                    'payment_method' => $payment_method->slug(),
664
-                                ),
665
-                                EE_PAYMENTS_ADMIN_URL
666
-                            ),
667
-                            $link_text_and_title,
668
-                            $link_text_and_title,
669
-                            'deactivate_' . $payment_method->slug(),
670
-                            'espresso-button button-secondary'
671
-                        )
672
-                    )
673
-                )
674
-            )
675
-        );
676
-    }
677
-
678
-
679
-    /**
680
-     * _activate_payment_method_button
681
-     *
682
-     * @access protected
683
-     * @param EE_Payment_Method $payment_method
684
-     * @return EE_Form_Section_Proper
685
-     */
686
-    protected function _activate_payment_method_button(EE_Payment_Method $payment_method)
687
-    {
688
-        $link_text_and_title = sprintf(
689
-            __('Activate %1$s Payment Method?', 'event_espresso'),
690
-            $payment_method->admin_name()
691
-        );
692
-        return new EE_Form_Section_Proper(
693
-            array(
694
-                'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
695
-                'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
696
-                'action'          => '#',
697
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
698
-                'subsections'     => apply_filters(
699
-                    'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections',
700
-                    array(
701
-                        new EE_Form_Section_HTML(
702
-                            EEH_HTML::table(
703
-                                EEH_HTML::tr(
704
-                                    EEH_HTML::td(
705
-                                        $payment_method->type_obj()->introductory_html(),
706
-                                        '',
707
-                                        '',
708
-                                        '',
709
-                                        'colspan="2"'
710
-                                    )
711
-                                ) .
712
-                                EEH_HTML::tr(
713
-                                    EEH_HTML::th(
714
-                                        EEH_HTML::label(__('Click to Activate ', 'event_espresso'))
715
-                                    ) .
716
-                                    EEH_HTML::td(
717
-                                        EEH_HTML::link(
718
-                                            EE_Admin_Page::add_query_args_and_nonce(
719
-                                                array(
720
-                                                    'action'              => 'activate_payment_method',
721
-                                                    'payment_method_type' => $payment_method->type(),
722
-                                                ),
723
-                                                EE_PAYMENTS_ADMIN_URL
724
-                                            ),
725
-                                            $link_text_and_title,
726
-                                            $link_text_and_title,
727
-                                            'activate_' . $payment_method->slug(),
728
-                                            'espresso-button-green button-primary'
729
-                                        )
730
-                                    )
731
-                                )
732
-                            )
733
-                        ),
734
-                    ),
735
-                    $payment_method
736
-                ),
737
-            )
738
-        );
739
-    }
740
-
741
-
742
-    /**
743
-     * _fine_print
744
-     *
745
-     * @access protected
746
-     * @return EE_Form_Section_HTML
747
-     */
748
-    protected function _fine_print()
749
-    {
750
-        return new EE_Form_Section_HTML(
751
-            EEH_HTML::table(
752
-                EEH_HTML::tr(
753
-                    EEH_HTML::th() .
754
-                    EEH_HTML::td(
755
-                        EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
756
-                    )
757
-                )
758
-            )
759
-        );
760
-    }
761
-
762
-
763
-    /**
764
-     * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far)
765
-     *
766
-     * @global WP_User $current_user
767
-     */
768
-    protected function _activate_payment_method()
769
-    {
770
-        if (isset($this->_req_data['payment_method_type'])) {
771
-            $payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']);
772
-            // see if one exists
773
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
774
-            $payment_method = EE_Payment_Method_Manager::instance()
775
-                                                       ->activate_a_payment_method_of_type($payment_method_type);
776
-            $this->_redirect_after_action(
777
-                1,
778
-                'Payment Method',
779
-                'activated',
780
-                array('action' => 'default', 'payment_method' => $payment_method->slug())
781
-            );
782
-        } else {
783
-            $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
784
-        }
785
-    }
786
-
787
-
788
-    /**
789
-     * Deactivates the payment method with the specified slug, and redirects.
790
-     */
791
-    protected function _deactivate_payment_method()
792
-    {
793
-        if (isset($this->_req_data['payment_method'])) {
794
-            $payment_method_slug = sanitize_key($this->_req_data['payment_method']);
795
-            // deactivate it
796
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
797
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug);
798
-            $this->_redirect_after_action(
799
-                $count_updated,
800
-                'Payment Method',
801
-                'deactivated',
802
-                array('action' => 'default', 'payment_method' => $payment_method_slug)
803
-            );
804
-        } else {
805
-            $this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default'));
806
-        }
807
-    }
808
-
809
-
810
-    /**
811
-     * Processes the payment method form that was submitted. This is slightly trickier than usual form
812
-     * processing because we first need to identify WHICH form was processed and which payment method
813
-     * it corresponds to. Once we have done that, we see if the form is valid. If it is, the
814
-     * form's data is saved and we redirect to the default payment methods page, setting the updated payment method
815
-     * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the
816
-     * subsequently called 'headers_sent_func' which is _payment_methods_list)
817
-     *
818
-     * @return void
819
-     */
820
-    protected function _update_payment_method()
821
-    {
822
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
823
-            // ok let's find which gateway form to use based on the form input
824
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
825
-            /** @var $correct_pmt_form_to_use EE_Payment_Method_Form */
826
-            $correct_pmt_form_to_use = null;
827
-            $payment_method = null;
828
-            foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) {
829
-                // get the form and simplify it, like what we do when we display it
830
-                $pmt_form = $this->_generate_payment_method_settings_form($payment_method);
831
-                if ($pmt_form->form_data_present_in($this->_req_data)) {
832
-                    $correct_pmt_form_to_use = $pmt_form;
833
-                    break;
834
-                }
835
-            }
836
-            // if we couldn't find the correct payment method type...
837
-            if (! $correct_pmt_form_to_use) {
838
-                EE_Error::add_error(
839
-                    __(
840
-                        "We could not find which payment method type your form submission related to. Please contact support",
841
-                        'event_espresso'
842
-                    ),
843
-                    __FILE__,
844
-                    __FUNCTION__,
845
-                    __LINE__
846
-                );
847
-                $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
848
-            }
849
-            $correct_pmt_form_to_use->receive_form_submission($this->_req_data);
850
-            if ($correct_pmt_form_to_use->is_valid()) {
851
-                $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
852
-                if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
853
-                    throw new EE_Error(
854
-                        sprintf(
855
-                            __(
856
-                                'The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.',
857
-                                'event_espresso'
858
-                            ),
859
-                            'payment_method_settings'
860
-                        )
861
-                    );
862
-                }
863
-                $payment_settings_subform->save();
864
-                /** @var $pm EE_Payment_Method */
865
-                $this->_redirect_after_action(
866
-                    true,
867
-                    'Payment Method',
868
-                    'updated',
869
-                    array('action' => 'default', 'payment_method' => $payment_method->slug())
870
-                );
871
-            } else {
872
-                EE_Error::add_error(
873
-                    sprintf(
874
-                        __(
875
-                            'Payment method of type %s was not saved because there were validation errors. They have been marked in the form',
876
-                            'event_espresso'
877
-                        ),
878
-                        $payment_method instanceof EE_Payment_Method ? $payment_method->type_obj()->pretty_name()
879
-                            : __('"(unknown)"', 'event_espresso')
880
-                    ),
881
-                    __FILE__,
882
-                    __FUNCTION__,
883
-                    __LINE__
884
-                );
885
-            }
886
-        }
887
-        return;
888
-    }
889
-
890
-
891
-    /**
892
-     * Displays payment settings (not payment METHOD settings, that's _payment_method_settings)
893
-     * @throws DomainException
894
-     * @throws EE_Error
895
-     * @throws InvalidArgumentException
896
-     * @throws InvalidDataTypeException
897
-     * @throws InvalidInterfaceException
898
-     */
899
-    protected function _payment_settings()
900
-    {
901
-        $form = $this->getPaymentSettingsForm();
902
-        $this->_set_add_edit_form_tags('update_payment_settings');
903
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
904
-        $this->_template_args['admin_page_content'] =  $form->get_html_and_js();
905
-        $this->display_admin_page_with_sidebar();
906
-    }
907
-
908
-
909
-    /**
910
-     *        _update_payment_settings
911
-     *
912
-     * @access protected
913
-     * @return void
914
-     * @throws EE_Error
915
-     * @throws InvalidArgumentException
916
-     * @throws InvalidDataTypeException
917
-     * @throws InvalidInterfaceException
918
-     */
919
-    protected function _update_payment_settings()
920
-    {
921
-        $form = $this->getPaymentSettingsForm();
922
-        if ($form->was_submitted($this->_req_data)) {
923
-            $form->receive_form_submission($this->_req_data);
924
-            if ($form->is_valid()) {
925
-                /**
926
-                 * @var $reg_config EE_Registration_Config
927
-                 */
928
-                $loader = LoaderFactory::getLoader();
929
-                $reg_config = $loader->getShared('EE_Registration_Config');
930
-                $valid_data = $form->valid_data();
931
-                $reg_config->show_pending_payment_options = $valid_data['show_pending_payment_options'];
932
-                $reg_config->gateway_log_lifespan = $valid_data['gateway_log_lifespan'];
933
-            }
934
-        }
935
-        EE_Registry::instance()->CFG = apply_filters(
936
-            'FHEE__Payments_Admin_Page___update_payment_settings__CFG',
937
-            EE_Registry::instance()->CFG
938
-        );
939
-
940
-        $cfg =  EE_Registry::instance()->CFG ;
941
-
942
-        $what = __('Payment Settings', 'event_espresso');
943
-        $success = $this->_update_espresso_configuration(
944
-            $what,
945
-            EE_Registry::instance()->CFG,
946
-            __FILE__,
947
-            __FUNCTION__,
948
-            __LINE__
949
-        );
950
-        $this->_redirect_after_action(
951
-            $success,
952
-            $what,
953
-            __('updated', 'event_espresso'),
954
-            array('action' => 'payment_settings')
955
-        );
956
-    }
957
-
958
-
959
-    /**
960
-     * Gets the form used for updating payment settings
961
-     *
962
-     * @return EE_Form_Section_Proper
963
-     * @throws EE_Error
964
-     * @throws InvalidArgumentException
965
-     * @throws InvalidDataTypeException
966
-     * @throws InvalidInterfaceException
967
-     */
968
-    protected function getPaymentSettingsForm()
969
-    {
970
-        /**
971
-         * @var $reg_config EE_Registration_Config
972
-         */
973
-        $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
974
-        return new EE_Form_Section_Proper(
975
-            array(
976
-                'name' => 'payment-settings',
977
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
978
-                'subsections' => array(
979
-                    'show_pending_payment_options' => new EE_Yes_No_Input(
980
-                        array(
981
-                            'html_name' => 'show_pending_payment_options',
982
-                            'default' => $reg_config->show_pending_payment_options,
983
-                            'html_help_text' => esc_html__(
984
-                                "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. ",
985
-                                'event_espresso'
986
-                            )
987
-                        )
988
-                    ),
989
-                    'gateway_log_lifespan' => new EE_Select_Input(
990
-                        $reg_config->gatewayLogLifespanOptions(),
991
-                        array(
992
-                            'html_label_text' => esc_html__('Gateway Logs Lifespan', 'event_espresso'),
993
-                            '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'),
994
-                            'default' => $reg_config->gateway_log_lifespan,
995
-                        )
996
-                    )
997
-                )
998
-            )
999
-        );
1000
-    }
1001
-
1002
-
1003
-    protected function _payment_log_overview_list_table()
1004
-    {
1005
-        $this->display_admin_list_table_page_with_sidebar();
1006
-    }
1007
-
1008
-
1009
-    protected function _set_list_table_views_payment_log()
1010
-    {
1011
-        $this->_views = array(
1012
-            'all' => array(
1013
-                'slug'  => 'all',
1014
-                'label' => __('View All Logs', 'event_espresso'),
1015
-                'count' => 0,
1016
-            ),
1017
-        );
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     * @param int  $per_page
1023
-     * @param int  $current_page
1024
-     * @param bool $count
1025
-     * @return array
1026
-     */
1027
-    public function get_payment_logs($per_page = 50, $current_page = 0, $count = false)
1028
-    {
1029
-        EE_Registry::instance()->load_model('Change_Log');
1030
-        // we may need to do multiple queries (joining differently), so we actually wan tan array of query params
1031
-        $query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway));
1032
-        // check if they've selected a specific payment method
1033
-        if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') {
1034
-            $query_params[0]['OR*pm_or_pay_pm'] = array(
1035
-                'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'],
1036
-                'Payment_Method.PMD_ID'         => $this->_req_data['_payment_method'],
1037
-            );
1038
-        }
1039
-        // take into account search
1040
-        if (isset($this->_req_data['s']) && $this->_req_data['s']) {
1041
-            $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
1042
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
1043
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
1044
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
1045
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string;
1046
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string;
1047
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string;
1048
-            $query_params[0]['OR*s']['LOG_message'] = $similarity_string;
1049
-            $query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string;
1050
-            $query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string;
1051
-            $query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string;
1052
-            $query_params[0]['OR*s']['LOG_message'] = $similarity_string;
1053
-        }
1054
-        if (isset($this->_req_data['payment-filter-start-date'])
1055
-            && isset($this->_req_data['payment-filter-end-date'])
1056
-        ) {
1057
-            // add date
1058
-            $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
1059
-            $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
1060
-            // make sure our timestamps start and end right at the boundaries for each day
1061
-            $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1062
-            $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1063
-            // convert to timestamps
1064
-            $start_date = strtotime($start_date);
1065
-            $end_date = strtotime($end_date);
1066
-            // makes sure start date is the lowest value and vice versa
1067
-            $start_date = min($start_date, $end_date);
1068
-            $end_date = max($start_date, $end_date);
1069
-            // convert for query
1070
-            $start_date = EEM_Change_Log::instance()
1071
-                                        ->convert_datetime_for_query(
1072
-                                            'LOG_time',
1073
-                                            date('Y-m-d H:i:s', $start_date),
1074
-                                            'Y-m-d H:i:s'
1075
-                                        );
1076
-            $end_date = EEM_Change_Log::instance()
1077
-                                      ->convert_datetime_for_query(
1078
-                                          'LOG_time',
1079
-                                          date('Y-m-d H:i:s', $end_date),
1080
-                                          'Y-m-d H:i:s'
1081
-                                      );
1082
-            $query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date));
1083
-        }
1084
-        if ($count) {
1085
-            return EEM_Change_Log::instance()->count($query_params);
1086
-        }
1087
-        if (isset($this->_req_data['order'])) {
1088
-            $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
1089
-                : 'DESC';
1090
-            $query_params['order_by'] = array('LOG_time' => $sort);
1091
-        } else {
1092
-            $query_params['order_by'] = array('LOG_time' => 'DESC');
1093
-        }
1094
-        $offset = ($current_page - 1) * $per_page;
1095
-        if (! isset($this->_req_data['download_results'])) {
1096
-            $query_params['limit'] = array($offset, $per_page);
1097
-        }
1098
-        // now they've requested to instead just download the file instead of viewing it.
1099
-        if (isset($this->_req_data['download_results'])) {
1100
-            $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
1101
-            header('Content-Disposition: attachment');
1102
-            header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
1103
-            echo "<h1>Payment Logs for " . site_url() . "</h1>";
1104
-            echo "<h3>Query:</h3>";
1105
-            var_dump($query_params);
1106
-            echo "<h3>Results:</h3>";
1107
-            var_dump($wpdb_results);
1108
-            die;
1109
-        }
1110
-        $results = EEM_Change_Log::instance()->get_all($query_params);
1111
-        return $results;
1112
-    }
1113
-
1114
-
1115
-    /**
1116
-     * Used by usort to RE-sort log query results, because we lose the ordering
1117
-     * because we're possibly combining the results from two queries
1118
-     *
1119
-     * @param EE_Change_Log $logA
1120
-     * @param EE_Change_Log $logB
1121
-     * @return int
1122
-     */
1123
-    protected function _sort_logs_again($logA, $logB)
1124
-    {
1125
-        $timeA = $logA->get_raw('LOG_time');
1126
-        $timeB = $logB->get_raw('LOG_time');
1127
-        if ($timeA == $timeB) {
1128
-            return 0;
1129
-        }
1130
-        $comparison = $timeA < $timeB ? -1 : 1;
1131
-        if (strtoupper($this->_sort_logs_again_direction) == 'DESC') {
1132
-            return $comparison * -1;
1133
-        } else {
1134
-            return $comparison;
1135
-        }
1136
-    }
1137
-
1138
-
1139
-    protected function _payment_log_details()
1140
-    {
1141
-        EE_Registry::instance()->load_model('Change_Log');
1142
-        /** @var $payment_log EE_Change_Log */
1143
-        $payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']);
1144
-        $payment_method = null;
1145
-        $transaction = null;
1146
-        if ($payment_log instanceof EE_Change_Log) {
1147
-            if ($payment_log->object() instanceof EE_Payment) {
1148
-                $payment_method = $payment_log->object()->payment_method();
1149
-                $transaction = $payment_log->object()->transaction();
1150
-            } elseif ($payment_log->object() instanceof EE_Payment_Method) {
1151
-                $payment_method = $payment_log->object();
1152
-            } elseif ($payment_log->object() instanceof EE_Transaction) {
1153
-                $transaction = $payment_log->object();
1154
-                $payment_method = $transaction->payment_method();
1155
-            }
1156
-        }
1157
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1158
-            EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1159
-            array(
1160
-                'payment_log'    => $payment_log,
1161
-                'payment_method' => $payment_method,
1162
-                'transaction'    => $transaction,
1163
-            ),
1164
-            true
1165
-        );
1166
-        $this->display_admin_page_with_sidebar();
1167
-    }
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
+			'help_tour'     => array('Payment_Methods_Selection_Help_Tour'),
138
+			'require_nonce' => false,
139
+		);
140
+		$this->_page_config = array(
141
+			'default'          => $payment_method_list_config,
142
+			'payment_settings' => array(
143
+				'nav'           => array(
144
+					'label' => __('Settings', 'event_espresso'),
145
+					'order' => 20,
146
+				),
147
+				'help_tabs'     => array(
148
+					'payment_methods_settings_help_tab' => array(
149
+						'title'    => __('Payment Method Settings', 'event_espresso'),
150
+						'filename' => 'payment_methods_settings',
151
+					),
152
+				),
153
+				// 'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ),
154
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
155
+				'require_nonce' => false,
156
+			),
157
+			'payment_log'      => array(
158
+				'nav'           => array(
159
+					'label' => __("Logs", 'event_espresso'),
160
+					'order' => 30,
161
+				),
162
+				'list_table'    => 'Payment_Log_Admin_List_Table',
163
+				'metaboxes'     => $this->_default_espresso_metaboxes,
164
+				'require_nonce' => false,
165
+			),
166
+		);
167
+	}
168
+
169
+
170
+	/**
171
+	 * @return array
172
+	 * @throws DomainException
173
+	 * @throws EE_Error
174
+	 * @throws InvalidArgumentException
175
+	 * @throws InvalidDataTypeException
176
+	 * @throws InvalidInterfaceException
177
+	 * @throws ReflectionException
178
+	 */
179
+	protected function _add_payment_method_help_tabs()
180
+	{
181
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
182
+		$payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types();
183
+		$all_pmt_help_tabs_config = array();
184
+		foreach ($payment_method_types as $payment_method_type) {
185
+			if (! EE_Registry::instance()->CAP->current_user_can(
186
+				$payment_method_type->cap_name(),
187
+				'specific_payment_method_type_access'
188
+			)
189
+			) {
190
+				continue;
191
+			}
192
+			foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
193
+				$template_args = isset($config['template_args']) ? $config['template_args'] : array();
194
+				$template_args['admin_page_obj'] = $this;
195
+				$all_pmt_help_tabs_config[ $help_tab_name ] = array(
196
+					'title'   => $config['title'],
197
+					'content' => EEH_Template::display_template(
198
+						$payment_method_type->file_folder() . 'help_tabs/' . $config['filename'] . '.help_tab.php',
199
+						$template_args,
200
+						true
201
+					),
202
+				);
203
+			}
204
+		}
205
+		return $all_pmt_help_tabs_config;
206
+	}
207
+
208
+
209
+	// none of the below group are currently used for Gateway Settings
210
+	protected function _add_screen_options()
211
+	{
212
+	}
213
+
214
+
215
+	protected function _add_feature_pointers()
216
+	{
217
+	}
218
+
219
+
220
+	public function admin_init()
221
+	{
222
+	}
223
+
224
+
225
+	public function admin_notices()
226
+	{
227
+	}
228
+
229
+
230
+	public function admin_footer_scripts()
231
+	{
232
+	}
233
+
234
+
235
+	public function load_scripts_styles()
236
+	{
237
+		// styles
238
+		wp_enqueue_style('espresso-ui-theme');
239
+		// scripts
240
+		wp_enqueue_script('ee_admin_js');
241
+		wp_enqueue_script('ee-text-links');
242
+		wp_enqueue_script(
243
+			'espresso_payments',
244
+			EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
245
+			array('ee-datepicker'),
246
+			EVENT_ESPRESSO_VERSION,
247
+			true
248
+		);
249
+	}
250
+
251
+
252
+	public function load_scripts_styles_default()
253
+	{
254
+		// styles
255
+		wp_register_style(
256
+			'espresso_payments',
257
+			EE_PAYMENTS_ASSETS_URL . 'ee-payments.css',
258
+			array(),
259
+			EVENT_ESPRESSO_VERSION
260
+		);
261
+		wp_enqueue_style('espresso_payments');
262
+		wp_enqueue_style('ee-text-links');
263
+		// scripts
264
+	}
265
+
266
+
267
+	protected function _payment_methods_list()
268
+	{
269
+		/**
270
+		 * first let's ensure payment methods have been setup. We do this here because when people activate a
271
+		 * payment method for the first time (as an addon), it may not setup its capabilities or get registered
272
+		 * correctly due to the loading process.  However, people MUST setup the details for the payment method so its
273
+		 * safe to do a recheck here.
274
+		 */
275
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
276
+		EEM_Payment_Method::instance()->verify_button_urls();
277
+		// setup tabs, one for each payment method type
278
+		$tabs = array();
279
+		$payment_methods = array();
280
+		foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) {
281
+			// we don't want to show admin-only PMTs for now
282
+			if ($pmt_obj instanceof EE_PMT_Admin_Only) {
283
+				continue;
284
+			}
285
+			// check access
286
+			if (! EE_Registry::instance()->CAP->current_user_can(
287
+				$pmt_obj->cap_name(),
288
+				'specific_payment_method_type_access'
289
+			)
290
+			) {
291
+				continue;
292
+			}
293
+			// check for any active pms of that type
294
+			$payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
295
+			if (! $payment_method instanceof EE_Payment_Method) {
296
+				$payment_method = EE_Payment_Method::new_instance(
297
+					array(
298
+						'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
299
+						'PMD_type'       => $pmt_obj->system_name(),
300
+						'PMD_name'       => $pmt_obj->pretty_name(),
301
+						'PMD_admin_name' => $pmt_obj->pretty_name(),
302
+					)
303
+				);
304
+			}
305
+			$payment_methods[ $payment_method->slug() ] = $payment_method;
306
+		}
307
+		$payment_methods = apply_filters(
308
+			'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
309
+			$payment_methods
310
+		);
311
+		foreach ($payment_methods as $payment_method) {
312
+			if ($payment_method instanceof EE_Payment_Method) {
313
+				add_meta_box(
314
+					// html id
315
+					'espresso_' . $payment_method->slug() . '_payment_settings',
316
+					// title
317
+					sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
318
+					// callback
319
+					array($this, 'payment_method_settings_meta_box'),
320
+					// post type
321
+					null,
322
+					// context
323
+					'normal',
324
+					// priority
325
+					'default',
326
+					// callback args
327
+					array('payment_method' => $payment_method)
328
+				);
329
+				// setup for tabbed content
330
+				$tabs[ $payment_method->slug() ] = array(
331
+					'label' => $payment_method->admin_name(),
332
+					'class' => $payment_method->active() ? 'gateway-active' : '',
333
+					'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
334
+					'title' => __('Modify this Payment Method', 'event_espresso'),
335
+					'slug'  => $payment_method->slug(),
336
+				);
337
+			}
338
+		}
339
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
340
+			$tabs,
341
+			'payment_method_links',
342
+			'|',
343
+			$this->_get_active_payment_method_slug()
344
+		);
345
+		$this->display_admin_page_with_sidebar();
346
+	}
347
+
348
+
349
+	/**
350
+	 *   _get_active_payment_method_slug
351
+	 *
352
+	 * @return string
353
+	 */
354
+	protected function _get_active_payment_method_slug()
355
+	{
356
+		$payment_method_slug = false;
357
+		// decide which payment method tab to open first, as dictated by the request's 'payment_method'
358
+		if (isset($this->_req_data['payment_method'])) {
359
+			// if they provided the current payment method, use it
360
+			$payment_method_slug = sanitize_key($this->_req_data['payment_method']);
361
+		}
362
+		$payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
363
+		// if that didn't work or wasn't provided, find another way to select the current pm
364
+		if (! $this->_verify_payment_method($payment_method)) {
365
+			// like, looking for an active one
366
+			$payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
367
+			// test that one as well
368
+			if ($this->_verify_payment_method($payment_method)) {
369
+				$payment_method_slug = $payment_method->slug();
370
+			} else {
371
+				$payment_method_slug = 'paypal_standard';
372
+			}
373
+		}
374
+		return $payment_method_slug;
375
+	}
376
+
377
+
378
+	/**
379
+	 *    payment_method_settings_meta_box
380
+	 *    returns TRUE if the passed payment method is properly constructed and the logged in user has the correct
381
+	 *    capabilities to access it
382
+	 *
383
+	 * @param EE_Payment_Method $payment_method
384
+	 * @return boolean
385
+	 */
386
+	protected function _verify_payment_method($payment_method)
387
+	{
388
+		if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base
389
+			&& EE_Registry::instance()->CAP->current_user_can(
390
+				$payment_method->type_obj()->cap_name(),
391
+				'specific_payment_method_type_access'
392
+			)
393
+		) {
394
+			return true;
395
+		}
396
+		return false;
397
+	}
398
+
399
+
400
+	/**
401
+	 *    payment_method_settings_meta_box
402
+	 *
403
+	 * @param NULL  $post_obj_which_is_null is an object containing the current post (as a $post object)
404
+	 * @param array $metabox                is an array with metabox id, title, callback, and args elements. the value
405
+	 *                                      at 'args' has key 'payment_method', as set within _payment_methods_list
406
+	 * @return string
407
+	 * @throws EE_Error
408
+	 */
409
+	public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox)
410
+	{
411
+		$payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
412
+			? $metabox['args']['payment_method'] : null;
413
+		if (! $payment_method instanceof EE_Payment_Method) {
414
+			throw new EE_Error(
415
+				sprintf(
416
+					__(
417
+						'Payment method metabox setup incorrectly. No Payment method object was supplied',
418
+						'event_espresso'
419
+					)
420
+				)
421
+			);
422
+		}
423
+		$payment_method_scopes = $payment_method->active();
424
+		// if the payment method really exists show its form, otherwise the activation template
425
+		if ($payment_method->ID() && ! empty($payment_method_scopes)) {
426
+			$form = $this->_generate_payment_method_settings_form($payment_method);
427
+			if ($form->form_data_present_in($this->_req_data)) {
428
+				$form->receive_form_submission($this->_req_data);
429
+			}
430
+			echo $form->form_open() . $form->get_html_and_js() . $form->form_close();
431
+		} else {
432
+			echo $this->_activate_payment_method_button($payment_method)->get_html_and_js();
433
+		}
434
+	}
435
+
436
+
437
+	/**
438
+	 * Gets the form for all the settings related to this payment method type
439
+	 *
440
+	 * @access protected
441
+	 * @param EE_Payment_Method $payment_method
442
+	 * @return EE_Form_Section_Proper
443
+	 */
444
+	protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method)
445
+	{
446
+		if (! $payment_method instanceof EE_Payment_Method) {
447
+			return new EE_Form_Section_Proper();
448
+		}
449
+		return new EE_Form_Section_Proper(
450
+			array(
451
+				'name'            => $payment_method->slug() . '_settings_form',
452
+				'html_id'         => $payment_method->slug() . '_settings_form',
453
+				'action'          => EE_Admin_Page::add_query_args_and_nonce(
454
+					array(
455
+						'action'         => 'update_payment_method',
456
+						'payment_method' => $payment_method->slug(),
457
+					),
458
+					EE_PAYMENTS_ADMIN_URL
459
+				),
460
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
461
+				'subsections'     => apply_filters(
462
+					'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections',
463
+					array(
464
+						'pci_dss_compliance'      => $this->_pci_dss_compliance($payment_method),
465
+						'currency_support'        => $this->_currency_support($payment_method),
466
+						'payment_method_settings' => $this->_payment_method_settings($payment_method),
467
+						'update'                  => $this->_update_payment_method_button($payment_method),
468
+						'deactivate'              => $this->_deactivate_payment_method_button($payment_method),
469
+						'fine_print'              => $this->_fine_print(),
470
+					),
471
+					$payment_method
472
+				),
473
+			)
474
+		);
475
+	}
476
+
477
+
478
+	/**
479
+	 * _pci_dss_compliance
480
+	 *
481
+	 * @access protected
482
+	 * @param EE_Payment_Method $payment_method
483
+	 * @return EE_Form_Section_Proper
484
+	 */
485
+	protected function _pci_dss_compliance(EE_Payment_Method $payment_method)
486
+	{
487
+		if ($payment_method->type_obj()->requires_https()) {
488
+			return new EE_Form_Section_HTML(
489
+				EEH_HTML::table(
490
+					EEH_HTML::tr(
491
+						EEH_HTML::th(
492
+							EEH_HTML::label(
493
+								EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
494
+							)
495
+						) .
496
+						EEH_HTML::td(
497
+							EEH_HTML::strong(
498
+								__(
499
+									'You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.',
500
+									'event_espresso'
501
+								)
502
+							)
503
+							.
504
+							EEH_HTML::br()
505
+							.
506
+							__('Learn more about ', 'event_espresso')
507
+							. EEH_HTML::link(
508
+								'https://www.pcisecuritystandards.org/merchants/index.php',
509
+								__('PCI DSS compliance', 'event_espresso')
510
+							)
511
+						)
512
+					)
513
+				)
514
+			);
515
+		} else {
516
+			return new EE_Form_Section_HTML('');
517
+		}
518
+	}
519
+
520
+
521
+	/**
522
+	 * _currency_support
523
+	 *
524
+	 * @access protected
525
+	 * @param EE_Payment_Method $payment_method
526
+	 * @return EE_Form_Section_Proper
527
+	 */
528
+	protected function _currency_support(EE_Payment_Method $payment_method)
529
+	{
530
+		if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
531
+			return new EE_Form_Section_HTML(
532
+				EEH_HTML::table(
533
+					EEH_HTML::tr(
534
+						EEH_HTML::th(
535
+							EEH_HTML::label(
536
+								EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
537
+							)
538
+						) .
539
+						EEH_HTML::td(
540
+							EEH_HTML::strong(
541
+								sprintf(
542
+									__(
543
+										'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.',
544
+										'event_espresso'
545
+									),
546
+									EE_Config::instance()->currency->code
547
+								)
548
+							)
549
+						)
550
+					)
551
+				)
552
+			);
553
+		} else {
554
+			return new EE_Form_Section_HTML('');
555
+		}
556
+	}
557
+
558
+
559
+	/**
560
+	 * _update_payment_method_button
561
+	 *
562
+	 * @access protected
563
+	 * @param EE_Payment_Method $payment_method
564
+	 * @return EE_Payment_Method_Form
565
+	 */
566
+	protected function _payment_method_settings(EE_Payment_Method $payment_method)
567
+	{
568
+		// modify the form so we only have/show fields that will be implemented for this version
569
+		return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name());
570
+	}
571
+
572
+
573
+	/**
574
+	 * Simplifies the form to merely reproduce 4.1's gateway settings functionality
575
+	 *
576
+	 * @param EE_Form_Section_Proper $form_section
577
+	 * @param string                 $payment_method_name
578
+	 * @return EE_Payment_Method_Form
579
+	 * @throws EE_Error
580
+	 */
581
+	protected function _simplify_form($form_section, $payment_method_name = '')
582
+	{
583
+		if ($form_section instanceof EE_Payment_Method_Form) {
584
+			$form_section->exclude(
585
+				array(
586
+					'PMD_type', // dont want them changing the type
587
+					'PMD_slug', // or the slug (probably never)
588
+					'PMD_wp_user', // or the user's ID
589
+					'Currency' // or the currency, until the rest of EE supports simultaneous currencies
590
+				)
591
+			);
592
+			return $form_section;
593
+		} else {
594
+			throw new EE_Error(
595
+				sprintf(
596
+					__(
597
+						'The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.',
598
+						'event_espresso'
599
+					),
600
+					$payment_method_name
601
+				)
602
+			);
603
+		}
604
+	}
605
+
606
+
607
+	/**
608
+	 * _update_payment_method_button
609
+	 *
610
+	 * @access protected
611
+	 * @param EE_Payment_Method $payment_method
612
+	 * @return EE_Form_Section_HTML
613
+	 */
614
+	protected function _update_payment_method_button(EE_Payment_Method $payment_method)
615
+	{
616
+		$update_button = new EE_Submit_Input(
617
+			array(
618
+				'name'       => 'submit',
619
+				'html_id'    => 'save_' . $payment_method->slug() . '_settings',
620
+				'default'    => sprintf(
621
+					__('Update %s Payment Settings', 'event_espresso'),
622
+					$payment_method->admin_name()
623
+				),
624
+				'html_label' => EEH_HTML::nbsp(),
625
+			)
626
+		);
627
+		return new EE_Form_Section_HTML(
628
+			EEH_HTML::table(
629
+				EEH_HTML::no_row(EEH_HTML::br(2)) .
630
+				EEH_HTML::tr(
631
+					EEH_HTML::th(__('Update Settings', 'event_espresso')) .
632
+					EEH_HTML::td(
633
+						$update_button->get_html_for_input()
634
+					)
635
+				)
636
+			)
637
+		);
638
+	}
639
+
640
+
641
+	/**
642
+	 * _deactivate_payment_method_button
643
+	 *
644
+	 * @access protected
645
+	 * @param EE_Payment_Method $payment_method
646
+	 * @return EE_Form_Section_Proper
647
+	 */
648
+	protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method)
649
+	{
650
+		$link_text_and_title = sprintf(
651
+			__('Deactivate %1$s Payments?', 'event_espresso'),
652
+			$payment_method->admin_name()
653
+		);
654
+		return new EE_Form_Section_HTML(
655
+			EEH_HTML::table(
656
+				EEH_HTML::tr(
657
+					EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) .
658
+					EEH_HTML::td(
659
+						EEH_HTML::link(
660
+							EE_Admin_Page::add_query_args_and_nonce(
661
+								array(
662
+									'action'         => 'deactivate_payment_method',
663
+									'payment_method' => $payment_method->slug(),
664
+								),
665
+								EE_PAYMENTS_ADMIN_URL
666
+							),
667
+							$link_text_and_title,
668
+							$link_text_and_title,
669
+							'deactivate_' . $payment_method->slug(),
670
+							'espresso-button button-secondary'
671
+						)
672
+					)
673
+				)
674
+			)
675
+		);
676
+	}
677
+
678
+
679
+	/**
680
+	 * _activate_payment_method_button
681
+	 *
682
+	 * @access protected
683
+	 * @param EE_Payment_Method $payment_method
684
+	 * @return EE_Form_Section_Proper
685
+	 */
686
+	protected function _activate_payment_method_button(EE_Payment_Method $payment_method)
687
+	{
688
+		$link_text_and_title = sprintf(
689
+			__('Activate %1$s Payment Method?', 'event_espresso'),
690
+			$payment_method->admin_name()
691
+		);
692
+		return new EE_Form_Section_Proper(
693
+			array(
694
+				'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
695
+				'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
696
+				'action'          => '#',
697
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
698
+				'subsections'     => apply_filters(
699
+					'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections',
700
+					array(
701
+						new EE_Form_Section_HTML(
702
+							EEH_HTML::table(
703
+								EEH_HTML::tr(
704
+									EEH_HTML::td(
705
+										$payment_method->type_obj()->introductory_html(),
706
+										'',
707
+										'',
708
+										'',
709
+										'colspan="2"'
710
+									)
711
+								) .
712
+								EEH_HTML::tr(
713
+									EEH_HTML::th(
714
+										EEH_HTML::label(__('Click to Activate ', 'event_espresso'))
715
+									) .
716
+									EEH_HTML::td(
717
+										EEH_HTML::link(
718
+											EE_Admin_Page::add_query_args_and_nonce(
719
+												array(
720
+													'action'              => 'activate_payment_method',
721
+													'payment_method_type' => $payment_method->type(),
722
+												),
723
+												EE_PAYMENTS_ADMIN_URL
724
+											),
725
+											$link_text_and_title,
726
+											$link_text_and_title,
727
+											'activate_' . $payment_method->slug(),
728
+											'espresso-button-green button-primary'
729
+										)
730
+									)
731
+								)
732
+							)
733
+						),
734
+					),
735
+					$payment_method
736
+				),
737
+			)
738
+		);
739
+	}
740
+
741
+
742
+	/**
743
+	 * _fine_print
744
+	 *
745
+	 * @access protected
746
+	 * @return EE_Form_Section_HTML
747
+	 */
748
+	protected function _fine_print()
749
+	{
750
+		return new EE_Form_Section_HTML(
751
+			EEH_HTML::table(
752
+				EEH_HTML::tr(
753
+					EEH_HTML::th() .
754
+					EEH_HTML::td(
755
+						EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
756
+					)
757
+				)
758
+			)
759
+		);
760
+	}
761
+
762
+
763
+	/**
764
+	 * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far)
765
+	 *
766
+	 * @global WP_User $current_user
767
+	 */
768
+	protected function _activate_payment_method()
769
+	{
770
+		if (isset($this->_req_data['payment_method_type'])) {
771
+			$payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']);
772
+			// see if one exists
773
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
774
+			$payment_method = EE_Payment_Method_Manager::instance()
775
+													   ->activate_a_payment_method_of_type($payment_method_type);
776
+			$this->_redirect_after_action(
777
+				1,
778
+				'Payment Method',
779
+				'activated',
780
+				array('action' => 'default', 'payment_method' => $payment_method->slug())
781
+			);
782
+		} else {
783
+			$this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
784
+		}
785
+	}
786
+
787
+
788
+	/**
789
+	 * Deactivates the payment method with the specified slug, and redirects.
790
+	 */
791
+	protected function _deactivate_payment_method()
792
+	{
793
+		if (isset($this->_req_data['payment_method'])) {
794
+			$payment_method_slug = sanitize_key($this->_req_data['payment_method']);
795
+			// deactivate it
796
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
797
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug);
798
+			$this->_redirect_after_action(
799
+				$count_updated,
800
+				'Payment Method',
801
+				'deactivated',
802
+				array('action' => 'default', 'payment_method' => $payment_method_slug)
803
+			);
804
+		} else {
805
+			$this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default'));
806
+		}
807
+	}
808
+
809
+
810
+	/**
811
+	 * Processes the payment method form that was submitted. This is slightly trickier than usual form
812
+	 * processing because we first need to identify WHICH form was processed and which payment method
813
+	 * it corresponds to. Once we have done that, we see if the form is valid. If it is, the
814
+	 * form's data is saved and we redirect to the default payment methods page, setting the updated payment method
815
+	 * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the
816
+	 * subsequently called 'headers_sent_func' which is _payment_methods_list)
817
+	 *
818
+	 * @return void
819
+	 */
820
+	protected function _update_payment_method()
821
+	{
822
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
823
+			// ok let's find which gateway form to use based on the form input
824
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
825
+			/** @var $correct_pmt_form_to_use EE_Payment_Method_Form */
826
+			$correct_pmt_form_to_use = null;
827
+			$payment_method = null;
828
+			foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) {
829
+				// get the form and simplify it, like what we do when we display it
830
+				$pmt_form = $this->_generate_payment_method_settings_form($payment_method);
831
+				if ($pmt_form->form_data_present_in($this->_req_data)) {
832
+					$correct_pmt_form_to_use = $pmt_form;
833
+					break;
834
+				}
835
+			}
836
+			// if we couldn't find the correct payment method type...
837
+			if (! $correct_pmt_form_to_use) {
838
+				EE_Error::add_error(
839
+					__(
840
+						"We could not find which payment method type your form submission related to. Please contact support",
841
+						'event_espresso'
842
+					),
843
+					__FILE__,
844
+					__FUNCTION__,
845
+					__LINE__
846
+				);
847
+				$this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
848
+			}
849
+			$correct_pmt_form_to_use->receive_form_submission($this->_req_data);
850
+			if ($correct_pmt_form_to_use->is_valid()) {
851
+				$payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
852
+				if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
853
+					throw new EE_Error(
854
+						sprintf(
855
+							__(
856
+								'The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.',
857
+								'event_espresso'
858
+							),
859
+							'payment_method_settings'
860
+						)
861
+					);
862
+				}
863
+				$payment_settings_subform->save();
864
+				/** @var $pm EE_Payment_Method */
865
+				$this->_redirect_after_action(
866
+					true,
867
+					'Payment Method',
868
+					'updated',
869
+					array('action' => 'default', 'payment_method' => $payment_method->slug())
870
+				);
871
+			} else {
872
+				EE_Error::add_error(
873
+					sprintf(
874
+						__(
875
+							'Payment method of type %s was not saved because there were validation errors. They have been marked in the form',
876
+							'event_espresso'
877
+						),
878
+						$payment_method instanceof EE_Payment_Method ? $payment_method->type_obj()->pretty_name()
879
+							: __('"(unknown)"', 'event_espresso')
880
+					),
881
+					__FILE__,
882
+					__FUNCTION__,
883
+					__LINE__
884
+				);
885
+			}
886
+		}
887
+		return;
888
+	}
889
+
890
+
891
+	/**
892
+	 * Displays payment settings (not payment METHOD settings, that's _payment_method_settings)
893
+	 * @throws DomainException
894
+	 * @throws EE_Error
895
+	 * @throws InvalidArgumentException
896
+	 * @throws InvalidDataTypeException
897
+	 * @throws InvalidInterfaceException
898
+	 */
899
+	protected function _payment_settings()
900
+	{
901
+		$form = $this->getPaymentSettingsForm();
902
+		$this->_set_add_edit_form_tags('update_payment_settings');
903
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
904
+		$this->_template_args['admin_page_content'] =  $form->get_html_and_js();
905
+		$this->display_admin_page_with_sidebar();
906
+	}
907
+
908
+
909
+	/**
910
+	 *        _update_payment_settings
911
+	 *
912
+	 * @access protected
913
+	 * @return void
914
+	 * @throws EE_Error
915
+	 * @throws InvalidArgumentException
916
+	 * @throws InvalidDataTypeException
917
+	 * @throws InvalidInterfaceException
918
+	 */
919
+	protected function _update_payment_settings()
920
+	{
921
+		$form = $this->getPaymentSettingsForm();
922
+		if ($form->was_submitted($this->_req_data)) {
923
+			$form->receive_form_submission($this->_req_data);
924
+			if ($form->is_valid()) {
925
+				/**
926
+				 * @var $reg_config EE_Registration_Config
927
+				 */
928
+				$loader = LoaderFactory::getLoader();
929
+				$reg_config = $loader->getShared('EE_Registration_Config');
930
+				$valid_data = $form->valid_data();
931
+				$reg_config->show_pending_payment_options = $valid_data['show_pending_payment_options'];
932
+				$reg_config->gateway_log_lifespan = $valid_data['gateway_log_lifespan'];
933
+			}
934
+		}
935
+		EE_Registry::instance()->CFG = apply_filters(
936
+			'FHEE__Payments_Admin_Page___update_payment_settings__CFG',
937
+			EE_Registry::instance()->CFG
938
+		);
939
+
940
+		$cfg =  EE_Registry::instance()->CFG ;
941
+
942
+		$what = __('Payment Settings', 'event_espresso');
943
+		$success = $this->_update_espresso_configuration(
944
+			$what,
945
+			EE_Registry::instance()->CFG,
946
+			__FILE__,
947
+			__FUNCTION__,
948
+			__LINE__
949
+		);
950
+		$this->_redirect_after_action(
951
+			$success,
952
+			$what,
953
+			__('updated', 'event_espresso'),
954
+			array('action' => 'payment_settings')
955
+		);
956
+	}
957
+
958
+
959
+	/**
960
+	 * Gets the form used for updating payment settings
961
+	 *
962
+	 * @return EE_Form_Section_Proper
963
+	 * @throws EE_Error
964
+	 * @throws InvalidArgumentException
965
+	 * @throws InvalidDataTypeException
966
+	 * @throws InvalidInterfaceException
967
+	 */
968
+	protected function getPaymentSettingsForm()
969
+	{
970
+		/**
971
+		 * @var $reg_config EE_Registration_Config
972
+		 */
973
+		$reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
974
+		return new EE_Form_Section_Proper(
975
+			array(
976
+				'name' => 'payment-settings',
977
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
978
+				'subsections' => array(
979
+					'show_pending_payment_options' => new EE_Yes_No_Input(
980
+						array(
981
+							'html_name' => 'show_pending_payment_options',
982
+							'default' => $reg_config->show_pending_payment_options,
983
+							'html_help_text' => esc_html__(
984
+								"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. ",
985
+								'event_espresso'
986
+							)
987
+						)
988
+					),
989
+					'gateway_log_lifespan' => new EE_Select_Input(
990
+						$reg_config->gatewayLogLifespanOptions(),
991
+						array(
992
+							'html_label_text' => esc_html__('Gateway Logs Lifespan', 'event_espresso'),
993
+							'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'),
994
+							'default' => $reg_config->gateway_log_lifespan,
995
+						)
996
+					)
997
+				)
998
+			)
999
+		);
1000
+	}
1001
+
1002
+
1003
+	protected function _payment_log_overview_list_table()
1004
+	{
1005
+		$this->display_admin_list_table_page_with_sidebar();
1006
+	}
1007
+
1008
+
1009
+	protected function _set_list_table_views_payment_log()
1010
+	{
1011
+		$this->_views = array(
1012
+			'all' => array(
1013
+				'slug'  => 'all',
1014
+				'label' => __('View All Logs', 'event_espresso'),
1015
+				'count' => 0,
1016
+			),
1017
+		);
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 * @param int  $per_page
1023
+	 * @param int  $current_page
1024
+	 * @param bool $count
1025
+	 * @return array
1026
+	 */
1027
+	public function get_payment_logs($per_page = 50, $current_page = 0, $count = false)
1028
+	{
1029
+		EE_Registry::instance()->load_model('Change_Log');
1030
+		// we may need to do multiple queries (joining differently), so we actually wan tan array of query params
1031
+		$query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway));
1032
+		// check if they've selected a specific payment method
1033
+		if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') {
1034
+			$query_params[0]['OR*pm_or_pay_pm'] = array(
1035
+				'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'],
1036
+				'Payment_Method.PMD_ID'         => $this->_req_data['_payment_method'],
1037
+			);
1038
+		}
1039
+		// take into account search
1040
+		if (isset($this->_req_data['s']) && $this->_req_data['s']) {
1041
+			$similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
1042
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
1043
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
1044
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
1045
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string;
1046
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string;
1047
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string;
1048
+			$query_params[0]['OR*s']['LOG_message'] = $similarity_string;
1049
+			$query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string;
1050
+			$query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string;
1051
+			$query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string;
1052
+			$query_params[0]['OR*s']['LOG_message'] = $similarity_string;
1053
+		}
1054
+		if (isset($this->_req_data['payment-filter-start-date'])
1055
+			&& isset($this->_req_data['payment-filter-end-date'])
1056
+		) {
1057
+			// add date
1058
+			$start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
1059
+			$end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
1060
+			// make sure our timestamps start and end right at the boundaries for each day
1061
+			$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1062
+			$end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1063
+			// convert to timestamps
1064
+			$start_date = strtotime($start_date);
1065
+			$end_date = strtotime($end_date);
1066
+			// makes sure start date is the lowest value and vice versa
1067
+			$start_date = min($start_date, $end_date);
1068
+			$end_date = max($start_date, $end_date);
1069
+			// convert for query
1070
+			$start_date = EEM_Change_Log::instance()
1071
+										->convert_datetime_for_query(
1072
+											'LOG_time',
1073
+											date('Y-m-d H:i:s', $start_date),
1074
+											'Y-m-d H:i:s'
1075
+										);
1076
+			$end_date = EEM_Change_Log::instance()
1077
+									  ->convert_datetime_for_query(
1078
+										  'LOG_time',
1079
+										  date('Y-m-d H:i:s', $end_date),
1080
+										  'Y-m-d H:i:s'
1081
+									  );
1082
+			$query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date));
1083
+		}
1084
+		if ($count) {
1085
+			return EEM_Change_Log::instance()->count($query_params);
1086
+		}
1087
+		if (isset($this->_req_data['order'])) {
1088
+			$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
1089
+				: 'DESC';
1090
+			$query_params['order_by'] = array('LOG_time' => $sort);
1091
+		} else {
1092
+			$query_params['order_by'] = array('LOG_time' => 'DESC');
1093
+		}
1094
+		$offset = ($current_page - 1) * $per_page;
1095
+		if (! isset($this->_req_data['download_results'])) {
1096
+			$query_params['limit'] = array($offset, $per_page);
1097
+		}
1098
+		// now they've requested to instead just download the file instead of viewing it.
1099
+		if (isset($this->_req_data['download_results'])) {
1100
+			$wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
1101
+			header('Content-Disposition: attachment');
1102
+			header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
1103
+			echo "<h1>Payment Logs for " . site_url() . "</h1>";
1104
+			echo "<h3>Query:</h3>";
1105
+			var_dump($query_params);
1106
+			echo "<h3>Results:</h3>";
1107
+			var_dump($wpdb_results);
1108
+			die;
1109
+		}
1110
+		$results = EEM_Change_Log::instance()->get_all($query_params);
1111
+		return $results;
1112
+	}
1113
+
1114
+
1115
+	/**
1116
+	 * Used by usort to RE-sort log query results, because we lose the ordering
1117
+	 * because we're possibly combining the results from two queries
1118
+	 *
1119
+	 * @param EE_Change_Log $logA
1120
+	 * @param EE_Change_Log $logB
1121
+	 * @return int
1122
+	 */
1123
+	protected function _sort_logs_again($logA, $logB)
1124
+	{
1125
+		$timeA = $logA->get_raw('LOG_time');
1126
+		$timeB = $logB->get_raw('LOG_time');
1127
+		if ($timeA == $timeB) {
1128
+			return 0;
1129
+		}
1130
+		$comparison = $timeA < $timeB ? -1 : 1;
1131
+		if (strtoupper($this->_sort_logs_again_direction) == 'DESC') {
1132
+			return $comparison * -1;
1133
+		} else {
1134
+			return $comparison;
1135
+		}
1136
+	}
1137
+
1138
+
1139
+	protected function _payment_log_details()
1140
+	{
1141
+		EE_Registry::instance()->load_model('Change_Log');
1142
+		/** @var $payment_log EE_Change_Log */
1143
+		$payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']);
1144
+		$payment_method = null;
1145
+		$transaction = null;
1146
+		if ($payment_log instanceof EE_Change_Log) {
1147
+			if ($payment_log->object() instanceof EE_Payment) {
1148
+				$payment_method = $payment_log->object()->payment_method();
1149
+				$transaction = $payment_log->object()->transaction();
1150
+			} elseif ($payment_log->object() instanceof EE_Payment_Method) {
1151
+				$payment_method = $payment_log->object();
1152
+			} elseif ($payment_log->object() instanceof EE_Transaction) {
1153
+				$transaction = $payment_log->object();
1154
+				$payment_method = $transaction->payment_method();
1155
+			}
1156
+		}
1157
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1158
+			EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1159
+			array(
1160
+				'payment_log'    => $payment_log,
1161
+				'payment_method' => $payment_method,
1162
+				'transaction'    => $transaction,
1163
+			),
1164
+			true
1165
+		);
1166
+		$this->display_admin_page_with_sidebar();
1167
+	}
1168 1168
 }
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
         $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types();
183 183
         $all_pmt_help_tabs_config = array();
184 184
         foreach ($payment_method_types as $payment_method_type) {
185
-            if (! EE_Registry::instance()->CAP->current_user_can(
185
+            if ( ! EE_Registry::instance()->CAP->current_user_can(
186 186
                 $payment_method_type->cap_name(),
187 187
                 'specific_payment_method_type_access'
188 188
             )
@@ -192,10 +192,10 @@  discard block
 block discarded – undo
192 192
             foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
193 193
                 $template_args = isset($config['template_args']) ? $config['template_args'] : array();
194 194
                 $template_args['admin_page_obj'] = $this;
195
-                $all_pmt_help_tabs_config[ $help_tab_name ] = array(
195
+                $all_pmt_help_tabs_config[$help_tab_name] = array(
196 196
                     'title'   => $config['title'],
197 197
                     'content' => EEH_Template::display_template(
198
-                        $payment_method_type->file_folder() . 'help_tabs/' . $config['filename'] . '.help_tab.php',
198
+                        $payment_method_type->file_folder().'help_tabs/'.$config['filename'].'.help_tab.php',
199 199
                         $template_args,
200 200
                         true
201 201
                     ),
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         wp_enqueue_script('ee-text-links');
242 242
         wp_enqueue_script(
243 243
             'espresso_payments',
244
-            EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
244
+            EE_PAYMENTS_ASSETS_URL.'espresso_payments_admin.js',
245 245
             array('ee-datepicker'),
246 246
             EVENT_ESPRESSO_VERSION,
247 247
             true
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
         // styles
255 255
         wp_register_style(
256 256
             'espresso_payments',
257
-            EE_PAYMENTS_ASSETS_URL . 'ee-payments.css',
257
+            EE_PAYMENTS_ASSETS_URL.'ee-payments.css',
258 258
             array(),
259 259
             EVENT_ESPRESSO_VERSION
260 260
         );
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
                 continue;
284 284
             }
285 285
             // check access
286
-            if (! EE_Registry::instance()->CAP->current_user_can(
286
+            if ( ! EE_Registry::instance()->CAP->current_user_can(
287 287
                 $pmt_obj->cap_name(),
288 288
                 'specific_payment_method_type_access'
289 289
             )
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
             }
293 293
             // check for any active pms of that type
294 294
             $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
295
-            if (! $payment_method instanceof EE_Payment_Method) {
295
+            if ( ! $payment_method instanceof EE_Payment_Method) {
296 296
                 $payment_method = EE_Payment_Method::new_instance(
297 297
                     array(
298 298
                         'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
                     )
303 303
                 );
304 304
             }
305
-            $payment_methods[ $payment_method->slug() ] = $payment_method;
305
+            $payment_methods[$payment_method->slug()] = $payment_method;
306 306
         }
307 307
         $payment_methods = apply_filters(
308 308
             'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
             if ($payment_method instanceof EE_Payment_Method) {
313 313
                 add_meta_box(
314 314
                     // html id
315
-                    'espresso_' . $payment_method->slug() . '_payment_settings',
315
+                    'espresso_'.$payment_method->slug().'_payment_settings',
316 316
                     // title
317 317
                     sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
318 318
                     // callback
@@ -327,10 +327,10 @@  discard block
 block discarded – undo
327 327
                     array('payment_method' => $payment_method)
328 328
                 );
329 329
                 // setup for tabbed content
330
-                $tabs[ $payment_method->slug() ] = array(
330
+                $tabs[$payment_method->slug()] = array(
331 331
                     'label' => $payment_method->admin_name(),
332 332
                     'class' => $payment_method->active() ? 'gateway-active' : '',
333
-                    'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
333
+                    'href'  => 'espresso_'.$payment_method->slug().'_payment_settings',
334 334
                     'title' => __('Modify this Payment Method', 'event_espresso'),
335 335
                     'slug'  => $payment_method->slug(),
336 336
                 );
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
         }
362 362
         $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
363 363
         // if that didn't work or wasn't provided, find another way to select the current pm
364
-        if (! $this->_verify_payment_method($payment_method)) {
364
+        if ( ! $this->_verify_payment_method($payment_method)) {
365 365
             // like, looking for an active one
366 366
             $payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
367 367
             // test that one as well
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
     {
411 411
         $payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
412 412
             ? $metabox['args']['payment_method'] : null;
413
-        if (! $payment_method instanceof EE_Payment_Method) {
413
+        if ( ! $payment_method instanceof EE_Payment_Method) {
414 414
             throw new EE_Error(
415 415
                 sprintf(
416 416
                     __(
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
             if ($form->form_data_present_in($this->_req_data)) {
428 428
                 $form->receive_form_submission($this->_req_data);
429 429
             }
430
-            echo $form->form_open() . $form->get_html_and_js() . $form->form_close();
430
+            echo $form->form_open().$form->get_html_and_js().$form->form_close();
431 431
         } else {
432 432
             echo $this->_activate_payment_method_button($payment_method)->get_html_and_js();
433 433
         }
@@ -443,13 +443,13 @@  discard block
 block discarded – undo
443 443
      */
444 444
     protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method)
445 445
     {
446
-        if (! $payment_method instanceof EE_Payment_Method) {
446
+        if ( ! $payment_method instanceof EE_Payment_Method) {
447 447
             return new EE_Form_Section_Proper();
448 448
         }
449 449
         return new EE_Form_Section_Proper(
450 450
             array(
451
-                'name'            => $payment_method->slug() . '_settings_form',
452
-                'html_id'         => $payment_method->slug() . '_settings_form',
451
+                'name'            => $payment_method->slug().'_settings_form',
452
+                'html_id'         => $payment_method->slug().'_settings_form',
453 453
                 'action'          => EE_Admin_Page::add_query_args_and_nonce(
454 454
                     array(
455 455
                         'action'         => 'update_payment_method',
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
                             EEH_HTML::label(
493 493
                                 EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
494 494
                             )
495
-                        ) .
495
+                        ).
496 496
                         EEH_HTML::td(
497 497
                             EEH_HTML::strong(
498 498
                                 __(
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
      */
528 528
     protected function _currency_support(EE_Payment_Method $payment_method)
529 529
     {
530
-        if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
530
+        if ( ! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
531 531
             return new EE_Form_Section_HTML(
532 532
                 EEH_HTML::table(
533 533
                     EEH_HTML::tr(
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
                             EEH_HTML::label(
536 536
                                 EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
537 537
                             )
538
-                        ) .
538
+                        ).
539 539
                         EEH_HTML::td(
540 540
                             EEH_HTML::strong(
541 541
                                 sprintf(
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
         $update_button = new EE_Submit_Input(
617 617
             array(
618 618
                 'name'       => 'submit',
619
-                'html_id'    => 'save_' . $payment_method->slug() . '_settings',
619
+                'html_id'    => 'save_'.$payment_method->slug().'_settings',
620 620
                 'default'    => sprintf(
621 621
                     __('Update %s Payment Settings', 'event_espresso'),
622 622
                     $payment_method->admin_name()
@@ -626,9 +626,9 @@  discard block
 block discarded – undo
626 626
         );
627 627
         return new EE_Form_Section_HTML(
628 628
             EEH_HTML::table(
629
-                EEH_HTML::no_row(EEH_HTML::br(2)) .
629
+                EEH_HTML::no_row(EEH_HTML::br(2)).
630 630
                 EEH_HTML::tr(
631
-                    EEH_HTML::th(__('Update Settings', 'event_espresso')) .
631
+                    EEH_HTML::th(__('Update Settings', 'event_espresso')).
632 632
                     EEH_HTML::td(
633 633
                         $update_button->get_html_for_input()
634 634
                     )
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
         return new EE_Form_Section_HTML(
655 655
             EEH_HTML::table(
656 656
                 EEH_HTML::tr(
657
-                    EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) .
657
+                    EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')).
658 658
                     EEH_HTML::td(
659 659
                         EEH_HTML::link(
660 660
                             EE_Admin_Page::add_query_args_and_nonce(
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
                             ),
667 667
                             $link_text_and_title,
668 668
                             $link_text_and_title,
669
-                            'deactivate_' . $payment_method->slug(),
669
+                            'deactivate_'.$payment_method->slug(),
670 670
                             'espresso-button button-secondary'
671 671
                         )
672 672
                     )
@@ -691,8 +691,8 @@  discard block
 block discarded – undo
691 691
         );
692 692
         return new EE_Form_Section_Proper(
693 693
             array(
694
-                'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
695
-                'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
694
+                'name'            => 'activate_'.$payment_method->slug().'_settings_form',
695
+                'html_id'         => 'activate_'.$payment_method->slug().'_settings_form',
696 696
                 'action'          => '#',
697 697
                 'layout_strategy' => new EE_Admin_Two_Column_Layout(),
698 698
                 'subsections'     => apply_filters(
@@ -708,11 +708,11 @@  discard block
 block discarded – undo
708 708
                                         '',
709 709
                                         'colspan="2"'
710 710
                                     )
711
-                                ) .
711
+                                ).
712 712
                                 EEH_HTML::tr(
713 713
                                     EEH_HTML::th(
714 714
                                         EEH_HTML::label(__('Click to Activate ', 'event_espresso'))
715
-                                    ) .
715
+                                    ).
716 716
                                     EEH_HTML::td(
717 717
                                         EEH_HTML::link(
718 718
                                             EE_Admin_Page::add_query_args_and_nonce(
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
                                             ),
725 725
                                             $link_text_and_title,
726 726
                                             $link_text_and_title,
727
-                                            'activate_' . $payment_method->slug(),
727
+                                            'activate_'.$payment_method->slug(),
728 728
                                             'espresso-button-green button-primary'
729 729
                                         )
730 730
                                     )
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
         return new EE_Form_Section_HTML(
751 751
             EEH_HTML::table(
752 752
                 EEH_HTML::tr(
753
-                    EEH_HTML::th() .
753
+                    EEH_HTML::th().
754 754
                     EEH_HTML::td(
755 755
                         EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
756 756
                     )
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
                 }
835 835
             }
836 836
             // if we couldn't find the correct payment method type...
837
-            if (! $correct_pmt_form_to_use) {
837
+            if ( ! $correct_pmt_form_to_use) {
838 838
                 EE_Error::add_error(
839 839
                     __(
840 840
                         "We could not find which payment method type your form submission related to. Please contact support",
@@ -849,7 +849,7 @@  discard block
 block discarded – undo
849 849
             $correct_pmt_form_to_use->receive_form_submission($this->_req_data);
850 850
             if ($correct_pmt_form_to_use->is_valid()) {
851 851
                 $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
852
-                if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
852
+                if ( ! $payment_settings_subform instanceof EE_Payment_Method_Form) {
853 853
                     throw new EE_Error(
854 854
                         sprintf(
855 855
                             __(
@@ -901,7 +901,7 @@  discard block
 block discarded – undo
901 901
         $form = $this->getPaymentSettingsForm();
902 902
         $this->_set_add_edit_form_tags('update_payment_settings');
903 903
         $this->_set_publish_post_box_vars(null, false, false, null, false);
904
-        $this->_template_args['admin_page_content'] =  $form->get_html_and_js();
904
+        $this->_template_args['admin_page_content'] = $form->get_html_and_js();
905 905
         $this->display_admin_page_with_sidebar();
906 906
     }
907 907
 
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
             EE_Registry::instance()->CFG
938 938
         );
939 939
 
940
-        $cfg =  EE_Registry::instance()->CFG ;
940
+        $cfg = EE_Registry::instance()->CFG;
941 941
 
942 942
         $what = __('Payment Settings', 'event_espresso');
943 943
         $success = $this->_update_espresso_configuration(
@@ -1038,7 +1038,7 @@  discard block
 block discarded – undo
1038 1038
         }
1039 1039
         // take into account search
1040 1040
         if (isset($this->_req_data['s']) && $this->_req_data['s']) {
1041
-            $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
1041
+            $similarity_string = array('LIKE', '%'.str_replace("", "%", $this->_req_data['s']).'%');
1042 1042
             $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
1043 1043
             $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
1044 1044
             $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
@@ -1058,8 +1058,8 @@  discard block
 block discarded – undo
1058 1058
             $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
1059 1059
             $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
1060 1060
             // make sure our timestamps start and end right at the boundaries for each day
1061
-            $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1062
-            $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1061
+            $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00';
1062
+            $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59';
1063 1063
             // convert to timestamps
1064 1064
             $start_date = strtotime($start_date);
1065 1065
             $end_date = strtotime($end_date);
@@ -1092,15 +1092,15 @@  discard block
 block discarded – undo
1092 1092
             $query_params['order_by'] = array('LOG_time' => 'DESC');
1093 1093
         }
1094 1094
         $offset = ($current_page - 1) * $per_page;
1095
-        if (! isset($this->_req_data['download_results'])) {
1095
+        if ( ! isset($this->_req_data['download_results'])) {
1096 1096
             $query_params['limit'] = array($offset, $per_page);
1097 1097
         }
1098 1098
         // now they've requested to instead just download the file instead of viewing it.
1099 1099
         if (isset($this->_req_data['download_results'])) {
1100 1100
             $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
1101 1101
             header('Content-Disposition: attachment');
1102
-            header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
1103
-            echo "<h1>Payment Logs for " . site_url() . "</h1>";
1102
+            header("Content-Disposition: attachment; filename=ee_payment_logs_for_".sanitize_key(site_url()));
1103
+            echo "<h1>Payment Logs for ".site_url()."</h1>";
1104 1104
             echo "<h3>Query:</h3>";
1105 1105
             var_dump($query_params);
1106 1106
             echo "<h3>Results:</h3>";
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
             }
1156 1156
         }
1157 1157
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1158
-            EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1158
+            EE_PAYMENTS_TEMPLATE_PATH.'payment_log_details.template.php',
1159 1159
             array(
1160 1160
                 'payment_log'    => $payment_log,
1161 1161
                 'payment_method' => $payment_method,
Please login to merge, or discard this patch.