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