Completed
Branch master (16f63d)
by
unknown
05:48
created
core/libraries/iframe_display/iframe_wrapper.template.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,11 +31,14 @@
 block discarded – undo
31 31
     <meta name="robots" content="noindex,nofollow">
32 32
     <?php if ($enqueue_wp_assets) : ?>
33 33
         <?php wp_head(); ?>
34
-    <?php else : ?>
34
+    <?php else {
35
+	: ?>
35 36
         <?php foreach ($css as $handle => $url) : ?>
36 37
             <?php if (isset($inline_styles["{$handle}_before"])) :?>
37 38
                 <style>
38
-                    <?php echo wp_kses($inline_styles["{$handle}_before"], AllowedTags::getWithFullTags()); ?>
39
+                    <?php echo wp_kses($inline_styles["{$handle}_before"], AllowedTags::getWithFullTags());
40
+}
41
+?>
39 42
                 </style>
40 43
             <?php endif; ?>
41 44
             <link rel="stylesheet" type="text/css" id="<?php esc_attr_e($handle); ?>" href="<?php echo esc_url_raw($url); ?>">
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_Payment_Method_Manager.lib.php 2 patches
Indentation   +597 added lines, -597 removed lines patch added patch discarded remove patch
@@ -17,601 +17,601 @@
 block discarded – undo
17 17
  */
18 18
 class EE_Payment_Method_Manager implements ResettableInterface
19 19
 {
20
-    /**
21
-     * prefix added to all payment method capabilities names
22
-     */
23
-    const CAPABILITIES_PREFIX = 'ee_payment_method_';
24
-
25
-    private static ?EE_Payment_Method_Manager $_instance = null;
26
-
27
-    /**
28
-     * @var boolean
29
-     */
30
-    protected bool $payment_method_caps_initialized = false;
31
-
32
-    /**
33
-     * @var string[] keys are class names without 'EE_PMT_', values are their filepaths
34
-     */
35
-    protected array $_payment_method_types = [];
36
-
37
-    /**
38
-     * @var EE_PMT_Base[]
39
-     */
40
-    protected array $payment_method_objects = [];
41
-
42
-
43
-    /**
44
-     * EE_Payment_Method_Manager constructor.
45
-     *
46
-     * @throws DomainException
47
-     */
48
-    public function __construct()
49
-    {
50
-        // if in admin lets ensure caps are set.
51
-        if (is_admin()) {
52
-            $this->_register_payment_methods();
53
-            // add PM caps when EE_Capabilities is initialized
54
-            add_action(
55
-                'AHEE__EE_Capabilities__init_caps__before_initialization',
56
-                [$this, 'initializePaymentMethodCaps']
57
-            );
58
-            // plus any time they get reset
59
-            add_filter(
60
-                'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
61
-                [$this, 'addPaymentMethodCapsDuringReset']
62
-            );
63
-        }
64
-        add_action('http_api_curl', ['EE_Payment_Method_Manager', 'curlRequestsToPaypalUseTls'], 10, 3);
65
-    }
66
-
67
-
68
-    /**
69
-     * @singleton method used to instantiate class object
70
-     * @return EE_Payment_Method_Manager instance
71
-     * @throws DomainException
72
-     * @throws EE_Error
73
-     * @throws ReflectionException
74
-     */
75
-    public static function instance(): EE_Payment_Method_Manager
76
-    {
77
-        // check if class object is instantiated, and instantiated properly
78
-        if (! self::$_instance instanceof EE_Payment_Method_Manager) {
79
-            EE_Registry::instance()->load_lib('PMT_Base');
80
-            self::$_instance = new self();
81
-        }
82
-        return self::$_instance;
83
-    }
84
-
85
-
86
-    /**
87
-     * Resets the instance and returns a new one
88
-     *
89
-     * @return EE_Payment_Method_Manager
90
-     * @throws DomainException
91
-     * @throws EE_Error
92
-     * @throws ReflectionException
93
-     */
94
-    public static function reset(): EE_Payment_Method_Manager
95
-    {
96
-        self::$_instance = null;
97
-        return self::instance();
98
-    }
99
-
100
-
101
-    /**
102
-     * Force posts to PayPal to use TLS v1.2. See:
103
-     * https://core.trac.wordpress.org/ticket/36320
104
-     * https://core.trac.wordpress.org/ticket/34924#comment:15
105
-     * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
106
-     * This will affect PayPal standard, pro, express, and Payflow.
107
-     *
108
-     * @param $handle
109
-     * @param $r
110
-     * @param $url
111
-     */
112
-    public static function curlRequestsToPaypalUseTls($handle, $r, $url)
113
-    {
114
-        if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) {
115
-            // Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
116
-            // instead of the constant because it might not be defined
117
-            curl_setopt($handle, CURLOPT_SSLVERSION, 6);
118
-        }
119
-    }
120
-
121
-
122
-    /**
123
-     * If necessary, re-register payment methods
124
-     *
125
-     * @param boolean $force_recheck whether to recheck for payment method types,
126
-     *                               or just re-use the PMTs we found last time we checked during this request (if
127
-     *                               we have not yet checked during this request, then we need to check anyways)
128
-     */
129
-    public function maybe_register_payment_methods(bool $force_recheck = false)
130
-    {
131
-        if (! $this->_payment_method_types || $force_recheck) {
132
-            $this->_register_payment_methods();
133
-        }
134
-    }
135
-
136
-
137
-    /**
138
-     * register_payment_methods
139
-     *
140
-     * @return array
141
-     */
142
-    protected function _register_payment_methods(): array
143
-    {
144
-        // grab list of installed modules
145
-        $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
146
-        // filter list of modules to register
147
-        $pm_to_register = apply_filters(
148
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
149
-            $pm_to_register
150
-        );
151
-        // remove any duplicates if that should happen for some reason
152
-        $pm_to_register = array_unique($pm_to_register);
153
-        // loop through folders
154
-        foreach ($pm_to_register as $pm_path) {
155
-            $this->register_payment_method($pm_path);
156
-        }
157
-        do_action(
158
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods',
159
-            $this->_payment_method_types
160
-        );
161
-        // filter list of installed modules
162
-        // keep them organized alphabetically by the payment method type's name
163
-        ksort($this->_payment_method_types);
164
-        return apply_filters(
165
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
166
-            $this->_payment_method_types
167
-        );
168
-    }
169
-
170
-
171
-    /**
172
-     * register_payment_method- makes core aware of this payment method
173
-     *
174
-     * @param string $payment_method_path - full path up to and including payment method folder
175
-     * @return boolean
176
-     */
177
-    public function register_payment_method(string $payment_method_path = ''): bool
178
-    {
179
-        do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
180
-        $module_ext = '.pm.php';
181
-        // make all separators match
182
-        $payment_method_path = rtrim(str_replace('/\\', '/', $payment_method_path), '/');
183
-        // grab and sanitize module name
184
-        $module_dir = basename($payment_method_path);
185
-        // create class name from module directory name
186
-        $module = str_replace(['_', ' '], [' ', '_'], $module_dir);
187
-        // add class prefix
188
-        $module_class = 'EE_PMT_' . $module;
189
-        // does the module exist ?
190
-        if (! is_readable($payment_method_path . '/' . $module_class . $module_ext)) {
191
-            $msg = sprintf(
192
-                esc_html__(
193
-                    'The requested %s payment method file could not be found or is not readable due to file permissions.',
194
-                    'event_espresso'
195
-                ),
196
-                $module
197
-            );
198
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
199
-            return false;
200
-        }
201
-        // load the module class file
202
-        require_once($payment_method_path . '/' . $module_class . $module_ext);
203
-        // verify that class exists
204
-        if (! class_exists($module_class)) {
205
-            $msg = sprintf(
206
-                esc_html__('The requested %s module class does not exist.', 'event_espresso'),
207
-                $module_class
208
-            );
209
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
210
-            return false;
211
-        }
212
-        // add to array of registered modules
213
-        $this->_payment_method_types[ $module ] = $payment_method_path . '/' . $module_class . $module_ext;
214
-        return true;
215
-    }
216
-
217
-
218
-    /**
219
-     * Checks if a payment method has been registered, and if so includes it
220
-     *
221
-     * @param string  $payment_method_name like 'PayPal_Pro', (ie class name without the prefix 'EEPM_')
222
-     * @param boolean $force_recheck       whether to force re-checking for new payment method types
223
-     * @return boolean
224
-     */
225
-    public function payment_method_type_exists(string $payment_method_name, bool $force_recheck = false): bool
226
-    {
227
-        if (
228
-            $force_recheck
229
-            || empty($this->_payment_method_types)
230
-            || ! isset($this->_payment_method_types[ $payment_method_name ])
231
-        ) {
232
-            $this->maybe_register_payment_methods($force_recheck);
233
-        }
234
-        if (isset($this->_payment_method_types[ $payment_method_name ])) {
235
-            require_once($this->_payment_method_types[ $payment_method_name ]);
236
-            return true;
237
-        }
238
-        return false;
239
-    }
240
-
241
-
242
-    /**
243
-     * Returns all the class names of the various payment method types
244
-     *
245
-     * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names'
246
-     *                               (what you'd find in wp_esp_payment_method.PMD_type)
247
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
248
-     * @return array
249
-     */
250
-    public function payment_method_type_names(bool $with_prefixes = false, bool $force_recheck = false): array
251
-    {
252
-        $this->maybe_register_payment_methods($force_recheck);
253
-        if ($with_prefixes) {
254
-            $classnames      = array_keys($this->_payment_method_types);
255
-            $payment_methods = [];
256
-            foreach ($classnames as $classname) {
257
-                $payment_methods[] = $this->payment_method_class_from_type($classname);
258
-            }
259
-            return $payment_methods;
260
-        }
261
-        return array_keys($this->_payment_method_types);
262
-    }
263
-
264
-
265
-    /**
266
-     * Gets an object of each payment method type, none of which are bound to a
267
-     * payment method instance
268
-     *
269
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
270
-     * @return EE_PMT_Base[]
271
-     */
272
-    public function payment_method_types(bool $force_recheck = false): array
273
-    {
274
-        if ($force_recheck || empty($this->payment_method_objects)) {
275
-            $this->maybe_register_payment_methods($force_recheck);
276
-            foreach ($this->payment_method_type_names(true) as $classname) {
277
-                if (! isset($this->payment_method_objects[ $classname ])) {
278
-                    $this->payment_method_objects[ $classname ] = new $classname();
279
-                }
280
-            }
281
-        }
282
-        return $this->payment_method_objects;
283
-    }
284
-
285
-
286
-    /**
287
-     * Changes the payment method's class name into the payment method type's name
288
-     * (as used on the payment method's table's PMD_type field)
289
-     *
290
-     * @param string $classname
291
-     * @return string
292
-     */
293
-    public function payment_method_type_sans_class_prefix(string $classname): string
294
-    {
295
-        return str_replace('EE_PMT_', '', $classname);
296
-    }
297
-
298
-
299
-    /**
300
-     * Does the opposite of payment-method_type_sans_prefix
301
-     *
302
-     * @param string $type
303
-     * @return string
304
-     */
305
-    public function payment_method_class_from_type(string $type): string
306
-    {
307
-        return 'EE_PMT_' . $type;
308
-    }
309
-
310
-
311
-    /**
312
-     * Activates a payment method of the given type.
313
-     *
314
-     * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
315
-     * @return EE_Payment_Method
316
-     * @throws InvalidDataTypeException
317
-     * @throws EE_Error
318
-     * @throws ReflectionException
319
-     */
320
-    public function activate_a_payment_method_of_type(string $payment_method_type): EE_Payment_Method
321
-    {
322
-        $this->maybe_register_payment_methods();
323
-        $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
324
-        if (! $payment_method instanceof EE_Payment_Method) {
325
-            $pm_type_class = $this->payment_method_class_from_type($payment_method_type);
326
-            if (class_exists($pm_type_class)) {
327
-                /** @var $pm_type_obj EE_PMT_Base */
328
-                $pm_type_obj    = new $pm_type_class();
329
-                $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
330
-                if (! $payment_method) {
331
-                    $payment_method = $this->create_payment_method_of_type($pm_type_obj);
332
-                }
333
-                $payment_method->set_type($payment_method_type);
334
-                $this->initialize_payment_method($payment_method);
335
-            } else {
336
-                throw new EE_Error(
337
-                    sprintf(
338
-                        esc_html__(
339
-                            'There is no payment method of type %1$s, so it could not be activated',
340
-                            'event_espresso'
341
-                        ),
342
-                        $pm_type_class
343
-                    )
344
-                );
345
-            }
346
-        }
347
-        $payment_method->set_active();
348
-        $payment_method->save();
349
-
350
-        // delete any auto-deactivation notices that may have been set
351
-        PersistentAdminNoticeManager::deletePersistentAdminNotice('auto-deactivated-' . $payment_method->slug());
352
-
353
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
354
-        // if this was the invoice message type, make sure users can view their invoices
355
-        if (
356
-            $payment_method->type() === 'Invoice'
357
-            && (
358
-            ! EEH_MSG_Template::is_mt_active('invoice')
359
-            )
360
-        ) {
361
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
362
-            /** @type EE_Message_Resource_Manager $message_resource_manager */
363
-            $message_resource_manager->ensure_message_type_is_active('invoice', 'html');
364
-            new PersistentAdminNotice(
365
-                'invoice_pm_requirements_notice',
366
-                sprintf(
367
-                    esc_html__(
368
-                        'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.',
369
-                        'event_espresso'
370
-                    ),
371
-                    '<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">',
372
-                    '</a>'
373
-                ),
374
-                true
375
-            );
376
-        }
377
-
378
-        do_action(
379
-            'AHEE__EE_Payment_Method_Manager__activate_a_payment_method_of_type__after_activation',
380
-            $payment_method,
381
-            $payment_method_type
382
-        );
383
-        return $payment_method;
384
-    }
385
-
386
-
387
-    /**
388
-     * Creates a payment method of the specified type. Does not save it.
389
-     *
390
-     * @param EE_PMT_Base $pm_type_obj
391
-     * @return EE_Payment_Method
392
-     * @throws EE_Error*@throws ReflectionException
393
-     * @throws ReflectionException
394
-     * @global WP_User    $current_user
395
-     */
396
-    public function create_payment_method_of_type(EE_PMT_Base $pm_type_obj): EE_Payment_Method
397
-    {
398
-        global $current_user;
399
-        return EE_Payment_Method::new_instance(
400
-            [
401
-                'PMD_type'       => $pm_type_obj->system_name(),
402
-                'PMD_name'       => $pm_type_obj->defaultFrontendName(),
403
-                'PMD_admin_name' => $pm_type_obj->pretty_name(),
404
-                'PMD_slug'       => $pm_type_obj->system_name(),// automatically converted to slug
405
-                'PMD_wp_user'    => $current_user->ID,
406
-                'PMD_order'      => EEM_Payment_Method::instance()->count(
407
-                    [['PMD_type' => ['!=', 'Admin_Only']]]
408
-                ) * 10,
409
-            ]
410
-        );
411
-    }
412
-
413
-
414
-    /**
415
-     * Sets the initial payment method properties (including extra meta)
416
-     *
417
-     * @param EE_Payment_Method $payment_method
418
-     * @return EE_Payment_Method
419
-     * @throws EE_Error
420
-     * @throws ReflectionException
421
-     */
422
-    public function initialize_payment_method(EE_Payment_Method $payment_method): EE_Payment_Method
423
-    {
424
-        $pm_type_obj = $payment_method->type_obj();
425
-        $payment_method->set_description($pm_type_obj->default_description());
426
-        if (! $payment_method->button_url()) {
427
-            $payment_method->set_button_url($pm_type_obj->default_button_url());
428
-        }
429
-        // now add setup its default extra meta properties
430
-        $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
431
-        if (! empty($extra_metas)) {
432
-            // verify the payment method has an ID before adding extra meta
433
-            if (! $payment_method->ID()) {
434
-                $payment_method->save();
435
-            }
436
-            foreach ($extra_metas as $meta_name => $input) {
437
-                $payment_method->update_extra_meta($meta_name, $input->raw_value());
438
-            }
439
-        }
440
-        return $payment_method;
441
-    }
442
-
443
-
444
-    /**
445
-     * Makes sure the payment method is related to the specified payment method
446
-     *
447
-     * @param EE_Payment_Method $payment_method
448
-     * @return EE_Payment_Method
449
-     * @deprecated in 4.9.40 because the currency payment method table is being deprecated
450
-     */
451
-    public function set_usable_currencies_on_payment_method(EE_Payment_Method $payment_method): EE_Payment_Method
452
-    {
453
-        EE_Error::doing_it_wrong(
454
-            'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method',
455
-            esc_html__(
456
-                'We no longer define what currencies are usable by payment methods. Its not used nor efficient.',
457
-                'event_espresso'
458
-            ),
459
-            '4.9.40'
460
-        );
461
-        return $payment_method;
462
-    }
463
-
464
-
465
-    /**
466
-     * Deactivates a payment method of the given payment method slug.
467
-     *
468
-     * @param string $payment_method_slug The slug for the payment method to deactivate.
469
-     * @return int count of rows updated.
470
-     * @throws EE_Error
471
-     * @throws ReflectionException
472
-     */
473
-    public function deactivate_payment_method(string $payment_method_slug): int
474
-    {
475
-        EE_Log::instance()->log(
476
-            __FILE__,
477
-            __FUNCTION__,
478
-            sprintf(
479
-                esc_html__(
480
-                    'Payment method with slug %1$s is being deactivated by site admin',
481
-                    'event_espresso'
482
-                ),
483
-                $payment_method_slug
484
-            ),
485
-            'payment_method_change'
486
-        );
487
-        $count_updated = EEM_Payment_Method::instance()->update(
488
-            ['PMD_scope' => []],
489
-            [['PMD_slug' => $payment_method_slug]]
490
-        );
491
-        do_action(
492
-            'AHEE__EE_Payment_Method_Manager__deactivate_payment_method__after_deactivating_payment_method',
493
-            $payment_method_slug,
494
-            $count_updated
495
-        );
496
-        return $count_updated;
497
-    }
498
-
499
-
500
-    /**
501
-     * initializes payment method access caps via EE_Capabilities::init_role_caps()
502
-     * upon EE_Payment_Method_Manager construction
503
-     *
504
-     * @throws EE_Error
505
-     * @throws DomainException
506
-     */
507
-    public function initializePaymentMethodCaps()
508
-    {
509
-        // don't do this twice
510
-        if ($this->payment_method_caps_initialized) {
511
-            return;
512
-        }
513
-        EE_Capabilities::instance()->addCaps(
514
-            $this->getPaymentMethodCaps()
515
-        );
516
-        $this->payment_method_caps_initialized = true;
517
-    }
518
-
519
-
520
-    /**
521
-     * array  of dynamic payment method access caps.
522
-     * at the time of writing, october 20 2014, these are the caps added:
523
-     *  ee_payment_method_admin_only
524
-     *  ee_payment_method_aim
525
-     *  ee_payment_method_bank
526
-     *  ee_payment_method_check
527
-     *  ee_payment_method_invoice
528
-     *  ee_payment_method_mijireh
529
-     *  ee_payment_method_paypal_pro
530
-     *  ee_payment_method_paypal_standard
531
-     * Any other payment methods added to core or via addons will also get
532
-     * their related capability automatically added too, so long as they are
533
-     * registered properly using EE_Register_Payment_Method::register()
534
-     *
535
-     * @return array
536
-     * @throws DomainException
537
-     */
538
-    protected function getPaymentMethodCaps(): array
539
-    {
540
-        $caps = [];
541
-        foreach ($this->payment_method_type_names() as $payment_method_name) {
542
-            $caps = $this->addPaymentMethodCap($payment_method_name, $caps);
543
-        }
544
-        return $caps;
545
-    }
546
-
547
-
548
-    /**
549
-     * @param string $payment_method_name
550
-     * @param array  $payment_method_caps
551
-     * @param string $role
552
-     * @return array
553
-     * @throws DomainException
554
-     */
555
-    public function addPaymentMethodCap(
556
-        string $payment_method_name,
557
-        array $payment_method_caps,
558
-        string $role = 'administrator'
559
-    ): array {
560
-        if (empty($payment_method_name)) {
561
-            throw new DomainException(
562
-                esc_html__(
563
-                    'The name of a payment method must be specified to add capabilities.',
564
-                    'event_espresso'
565
-                )
566
-            );
567
-        }
568
-        if (empty($role)) {
569
-            throw new DomainException(
570
-                sprintf(
571
-                    esc_html__(
572
-                        'No role was supplied while trying to add capabilities for the %1$s payment method.',
573
-                        'event_espresso'
574
-                    ),
575
-                    $payment_method_name
576
-                )
577
-            );
578
-        }
579
-        if (! isset($payment_method_caps[ $role ])) {
580
-            $payment_method_caps[ $role ] = [];
581
-        }
582
-        $payment_method_caps[ $role ][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX
583
-                                          . strtolower($payment_method_name);
584
-        return $payment_method_caps;
585
-    }
586
-
587
-
588
-    /**
589
-     * callback for FHEE__EE_Capabilities__init_role_caps__caps_map filter
590
-     * to add dynamic payment method access caps when capabilities are reset
591
-     * (or if that filter is called and PM caps are not already set)
592
-     *
593
-     * @param array $caps capabilities being filtered
594
-     * @param bool  $reset
595
-     * @return array
596
-     * @throws DomainException
597
-     */
598
-    public function addPaymentMethodCapsDuringReset(array $caps, bool $reset = false): array
599
-    {
600
-        if ($reset || ! $this->payment_method_caps_initialized) {
601
-            $this->payment_method_caps_initialized = true;
602
-            $caps                                  = array_merge_recursive($caps, $this->getPaymentMethodCaps());
603
-        }
604
-        return $caps;
605
-    }
606
-
607
-
608
-    /**
609
-     * @param $caps
610
-     * @return mixed
611
-     * @deprecated 4.9.42
612
-     */
613
-    public function add_payment_method_caps($caps)
614
-    {
615
-        return $caps;
616
-    }
20
+	/**
21
+	 * prefix added to all payment method capabilities names
22
+	 */
23
+	const CAPABILITIES_PREFIX = 'ee_payment_method_';
24
+
25
+	private static ?EE_Payment_Method_Manager $_instance = null;
26
+
27
+	/**
28
+	 * @var boolean
29
+	 */
30
+	protected bool $payment_method_caps_initialized = false;
31
+
32
+	/**
33
+	 * @var string[] keys are class names without 'EE_PMT_', values are their filepaths
34
+	 */
35
+	protected array $_payment_method_types = [];
36
+
37
+	/**
38
+	 * @var EE_PMT_Base[]
39
+	 */
40
+	protected array $payment_method_objects = [];
41
+
42
+
43
+	/**
44
+	 * EE_Payment_Method_Manager constructor.
45
+	 *
46
+	 * @throws DomainException
47
+	 */
48
+	public function __construct()
49
+	{
50
+		// if in admin lets ensure caps are set.
51
+		if (is_admin()) {
52
+			$this->_register_payment_methods();
53
+			// add PM caps when EE_Capabilities is initialized
54
+			add_action(
55
+				'AHEE__EE_Capabilities__init_caps__before_initialization',
56
+				[$this, 'initializePaymentMethodCaps']
57
+			);
58
+			// plus any time they get reset
59
+			add_filter(
60
+				'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
61
+				[$this, 'addPaymentMethodCapsDuringReset']
62
+			);
63
+		}
64
+		add_action('http_api_curl', ['EE_Payment_Method_Manager', 'curlRequestsToPaypalUseTls'], 10, 3);
65
+	}
66
+
67
+
68
+	/**
69
+	 * @singleton method used to instantiate class object
70
+	 * @return EE_Payment_Method_Manager instance
71
+	 * @throws DomainException
72
+	 * @throws EE_Error
73
+	 * @throws ReflectionException
74
+	 */
75
+	public static function instance(): EE_Payment_Method_Manager
76
+	{
77
+		// check if class object is instantiated, and instantiated properly
78
+		if (! self::$_instance instanceof EE_Payment_Method_Manager) {
79
+			EE_Registry::instance()->load_lib('PMT_Base');
80
+			self::$_instance = new self();
81
+		}
82
+		return self::$_instance;
83
+	}
84
+
85
+
86
+	/**
87
+	 * Resets the instance and returns a new one
88
+	 *
89
+	 * @return EE_Payment_Method_Manager
90
+	 * @throws DomainException
91
+	 * @throws EE_Error
92
+	 * @throws ReflectionException
93
+	 */
94
+	public static function reset(): EE_Payment_Method_Manager
95
+	{
96
+		self::$_instance = null;
97
+		return self::instance();
98
+	}
99
+
100
+
101
+	/**
102
+	 * Force posts to PayPal to use TLS v1.2. See:
103
+	 * https://core.trac.wordpress.org/ticket/36320
104
+	 * https://core.trac.wordpress.org/ticket/34924#comment:15
105
+	 * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
106
+	 * This will affect PayPal standard, pro, express, and Payflow.
107
+	 *
108
+	 * @param $handle
109
+	 * @param $r
110
+	 * @param $url
111
+	 */
112
+	public static function curlRequestsToPaypalUseTls($handle, $r, $url)
113
+	{
114
+		if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) {
115
+			// Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
116
+			// instead of the constant because it might not be defined
117
+			curl_setopt($handle, CURLOPT_SSLVERSION, 6);
118
+		}
119
+	}
120
+
121
+
122
+	/**
123
+	 * If necessary, re-register payment methods
124
+	 *
125
+	 * @param boolean $force_recheck whether to recheck for payment method types,
126
+	 *                               or just re-use the PMTs we found last time we checked during this request (if
127
+	 *                               we have not yet checked during this request, then we need to check anyways)
128
+	 */
129
+	public function maybe_register_payment_methods(bool $force_recheck = false)
130
+	{
131
+		if (! $this->_payment_method_types || $force_recheck) {
132
+			$this->_register_payment_methods();
133
+		}
134
+	}
135
+
136
+
137
+	/**
138
+	 * register_payment_methods
139
+	 *
140
+	 * @return array
141
+	 */
142
+	protected function _register_payment_methods(): array
143
+	{
144
+		// grab list of installed modules
145
+		$pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
146
+		// filter list of modules to register
147
+		$pm_to_register = apply_filters(
148
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
149
+			$pm_to_register
150
+		);
151
+		// remove any duplicates if that should happen for some reason
152
+		$pm_to_register = array_unique($pm_to_register);
153
+		// loop through folders
154
+		foreach ($pm_to_register as $pm_path) {
155
+			$this->register_payment_method($pm_path);
156
+		}
157
+		do_action(
158
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods',
159
+			$this->_payment_method_types
160
+		);
161
+		// filter list of installed modules
162
+		// keep them organized alphabetically by the payment method type's name
163
+		ksort($this->_payment_method_types);
164
+		return apply_filters(
165
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
166
+			$this->_payment_method_types
167
+		);
168
+	}
169
+
170
+
171
+	/**
172
+	 * register_payment_method- makes core aware of this payment method
173
+	 *
174
+	 * @param string $payment_method_path - full path up to and including payment method folder
175
+	 * @return boolean
176
+	 */
177
+	public function register_payment_method(string $payment_method_path = ''): bool
178
+	{
179
+		do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
180
+		$module_ext = '.pm.php';
181
+		// make all separators match
182
+		$payment_method_path = rtrim(str_replace('/\\', '/', $payment_method_path), '/');
183
+		// grab and sanitize module name
184
+		$module_dir = basename($payment_method_path);
185
+		// create class name from module directory name
186
+		$module = str_replace(['_', ' '], [' ', '_'], $module_dir);
187
+		// add class prefix
188
+		$module_class = 'EE_PMT_' . $module;
189
+		// does the module exist ?
190
+		if (! is_readable($payment_method_path . '/' . $module_class . $module_ext)) {
191
+			$msg = sprintf(
192
+				esc_html__(
193
+					'The requested %s payment method file could not be found or is not readable due to file permissions.',
194
+					'event_espresso'
195
+				),
196
+				$module
197
+			);
198
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
199
+			return false;
200
+		}
201
+		// load the module class file
202
+		require_once($payment_method_path . '/' . $module_class . $module_ext);
203
+		// verify that class exists
204
+		if (! class_exists($module_class)) {
205
+			$msg = sprintf(
206
+				esc_html__('The requested %s module class does not exist.', 'event_espresso'),
207
+				$module_class
208
+			);
209
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
210
+			return false;
211
+		}
212
+		// add to array of registered modules
213
+		$this->_payment_method_types[ $module ] = $payment_method_path . '/' . $module_class . $module_ext;
214
+		return true;
215
+	}
216
+
217
+
218
+	/**
219
+	 * Checks if a payment method has been registered, and if so includes it
220
+	 *
221
+	 * @param string  $payment_method_name like 'PayPal_Pro', (ie class name without the prefix 'EEPM_')
222
+	 * @param boolean $force_recheck       whether to force re-checking for new payment method types
223
+	 * @return boolean
224
+	 */
225
+	public function payment_method_type_exists(string $payment_method_name, bool $force_recheck = false): bool
226
+	{
227
+		if (
228
+			$force_recheck
229
+			|| empty($this->_payment_method_types)
230
+			|| ! isset($this->_payment_method_types[ $payment_method_name ])
231
+		) {
232
+			$this->maybe_register_payment_methods($force_recheck);
233
+		}
234
+		if (isset($this->_payment_method_types[ $payment_method_name ])) {
235
+			require_once($this->_payment_method_types[ $payment_method_name ]);
236
+			return true;
237
+		}
238
+		return false;
239
+	}
240
+
241
+
242
+	/**
243
+	 * Returns all the class names of the various payment method types
244
+	 *
245
+	 * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names'
246
+	 *                               (what you'd find in wp_esp_payment_method.PMD_type)
247
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
248
+	 * @return array
249
+	 */
250
+	public function payment_method_type_names(bool $with_prefixes = false, bool $force_recheck = false): array
251
+	{
252
+		$this->maybe_register_payment_methods($force_recheck);
253
+		if ($with_prefixes) {
254
+			$classnames      = array_keys($this->_payment_method_types);
255
+			$payment_methods = [];
256
+			foreach ($classnames as $classname) {
257
+				$payment_methods[] = $this->payment_method_class_from_type($classname);
258
+			}
259
+			return $payment_methods;
260
+		}
261
+		return array_keys($this->_payment_method_types);
262
+	}
263
+
264
+
265
+	/**
266
+	 * Gets an object of each payment method type, none of which are bound to a
267
+	 * payment method instance
268
+	 *
269
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
270
+	 * @return EE_PMT_Base[]
271
+	 */
272
+	public function payment_method_types(bool $force_recheck = false): array
273
+	{
274
+		if ($force_recheck || empty($this->payment_method_objects)) {
275
+			$this->maybe_register_payment_methods($force_recheck);
276
+			foreach ($this->payment_method_type_names(true) as $classname) {
277
+				if (! isset($this->payment_method_objects[ $classname ])) {
278
+					$this->payment_method_objects[ $classname ] = new $classname();
279
+				}
280
+			}
281
+		}
282
+		return $this->payment_method_objects;
283
+	}
284
+
285
+
286
+	/**
287
+	 * Changes the payment method's class name into the payment method type's name
288
+	 * (as used on the payment method's table's PMD_type field)
289
+	 *
290
+	 * @param string $classname
291
+	 * @return string
292
+	 */
293
+	public function payment_method_type_sans_class_prefix(string $classname): string
294
+	{
295
+		return str_replace('EE_PMT_', '', $classname);
296
+	}
297
+
298
+
299
+	/**
300
+	 * Does the opposite of payment-method_type_sans_prefix
301
+	 *
302
+	 * @param string $type
303
+	 * @return string
304
+	 */
305
+	public function payment_method_class_from_type(string $type): string
306
+	{
307
+		return 'EE_PMT_' . $type;
308
+	}
309
+
310
+
311
+	/**
312
+	 * Activates a payment method of the given type.
313
+	 *
314
+	 * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
315
+	 * @return EE_Payment_Method
316
+	 * @throws InvalidDataTypeException
317
+	 * @throws EE_Error
318
+	 * @throws ReflectionException
319
+	 */
320
+	public function activate_a_payment_method_of_type(string $payment_method_type): EE_Payment_Method
321
+	{
322
+		$this->maybe_register_payment_methods();
323
+		$payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
324
+		if (! $payment_method instanceof EE_Payment_Method) {
325
+			$pm_type_class = $this->payment_method_class_from_type($payment_method_type);
326
+			if (class_exists($pm_type_class)) {
327
+				/** @var $pm_type_obj EE_PMT_Base */
328
+				$pm_type_obj    = new $pm_type_class();
329
+				$payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
330
+				if (! $payment_method) {
331
+					$payment_method = $this->create_payment_method_of_type($pm_type_obj);
332
+				}
333
+				$payment_method->set_type($payment_method_type);
334
+				$this->initialize_payment_method($payment_method);
335
+			} else {
336
+				throw new EE_Error(
337
+					sprintf(
338
+						esc_html__(
339
+							'There is no payment method of type %1$s, so it could not be activated',
340
+							'event_espresso'
341
+						),
342
+						$pm_type_class
343
+					)
344
+				);
345
+			}
346
+		}
347
+		$payment_method->set_active();
348
+		$payment_method->save();
349
+
350
+		// delete any auto-deactivation notices that may have been set
351
+		PersistentAdminNoticeManager::deletePersistentAdminNotice('auto-deactivated-' . $payment_method->slug());
352
+
353
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
354
+		// if this was the invoice message type, make sure users can view their invoices
355
+		if (
356
+			$payment_method->type() === 'Invoice'
357
+			&& (
358
+			! EEH_MSG_Template::is_mt_active('invoice')
359
+			)
360
+		) {
361
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
362
+			/** @type EE_Message_Resource_Manager $message_resource_manager */
363
+			$message_resource_manager->ensure_message_type_is_active('invoice', 'html');
364
+			new PersistentAdminNotice(
365
+				'invoice_pm_requirements_notice',
366
+				sprintf(
367
+					esc_html__(
368
+						'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.',
369
+						'event_espresso'
370
+					),
371
+					'<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">',
372
+					'</a>'
373
+				),
374
+				true
375
+			);
376
+		}
377
+
378
+		do_action(
379
+			'AHEE__EE_Payment_Method_Manager__activate_a_payment_method_of_type__after_activation',
380
+			$payment_method,
381
+			$payment_method_type
382
+		);
383
+		return $payment_method;
384
+	}
385
+
386
+
387
+	/**
388
+	 * Creates a payment method of the specified type. Does not save it.
389
+	 *
390
+	 * @param EE_PMT_Base $pm_type_obj
391
+	 * @return EE_Payment_Method
392
+	 * @throws EE_Error*@throws ReflectionException
393
+	 * @throws ReflectionException
394
+	 * @global WP_User    $current_user
395
+	 */
396
+	public function create_payment_method_of_type(EE_PMT_Base $pm_type_obj): EE_Payment_Method
397
+	{
398
+		global $current_user;
399
+		return EE_Payment_Method::new_instance(
400
+			[
401
+				'PMD_type'       => $pm_type_obj->system_name(),
402
+				'PMD_name'       => $pm_type_obj->defaultFrontendName(),
403
+				'PMD_admin_name' => $pm_type_obj->pretty_name(),
404
+				'PMD_slug'       => $pm_type_obj->system_name(),// automatically converted to slug
405
+				'PMD_wp_user'    => $current_user->ID,
406
+				'PMD_order'      => EEM_Payment_Method::instance()->count(
407
+					[['PMD_type' => ['!=', 'Admin_Only']]]
408
+				) * 10,
409
+			]
410
+		);
411
+	}
412
+
413
+
414
+	/**
415
+	 * Sets the initial payment method properties (including extra meta)
416
+	 *
417
+	 * @param EE_Payment_Method $payment_method
418
+	 * @return EE_Payment_Method
419
+	 * @throws EE_Error
420
+	 * @throws ReflectionException
421
+	 */
422
+	public function initialize_payment_method(EE_Payment_Method $payment_method): EE_Payment_Method
423
+	{
424
+		$pm_type_obj = $payment_method->type_obj();
425
+		$payment_method->set_description($pm_type_obj->default_description());
426
+		if (! $payment_method->button_url()) {
427
+			$payment_method->set_button_url($pm_type_obj->default_button_url());
428
+		}
429
+		// now add setup its default extra meta properties
430
+		$extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
431
+		if (! empty($extra_metas)) {
432
+			// verify the payment method has an ID before adding extra meta
433
+			if (! $payment_method->ID()) {
434
+				$payment_method->save();
435
+			}
436
+			foreach ($extra_metas as $meta_name => $input) {
437
+				$payment_method->update_extra_meta($meta_name, $input->raw_value());
438
+			}
439
+		}
440
+		return $payment_method;
441
+	}
442
+
443
+
444
+	/**
445
+	 * Makes sure the payment method is related to the specified payment method
446
+	 *
447
+	 * @param EE_Payment_Method $payment_method
448
+	 * @return EE_Payment_Method
449
+	 * @deprecated in 4.9.40 because the currency payment method table is being deprecated
450
+	 */
451
+	public function set_usable_currencies_on_payment_method(EE_Payment_Method $payment_method): EE_Payment_Method
452
+	{
453
+		EE_Error::doing_it_wrong(
454
+			'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method',
455
+			esc_html__(
456
+				'We no longer define what currencies are usable by payment methods. Its not used nor efficient.',
457
+				'event_espresso'
458
+			),
459
+			'4.9.40'
460
+		);
461
+		return $payment_method;
462
+	}
463
+
464
+
465
+	/**
466
+	 * Deactivates a payment method of the given payment method slug.
467
+	 *
468
+	 * @param string $payment_method_slug The slug for the payment method to deactivate.
469
+	 * @return int count of rows updated.
470
+	 * @throws EE_Error
471
+	 * @throws ReflectionException
472
+	 */
473
+	public function deactivate_payment_method(string $payment_method_slug): int
474
+	{
475
+		EE_Log::instance()->log(
476
+			__FILE__,
477
+			__FUNCTION__,
478
+			sprintf(
479
+				esc_html__(
480
+					'Payment method with slug %1$s is being deactivated by site admin',
481
+					'event_espresso'
482
+				),
483
+				$payment_method_slug
484
+			),
485
+			'payment_method_change'
486
+		);
487
+		$count_updated = EEM_Payment_Method::instance()->update(
488
+			['PMD_scope' => []],
489
+			[['PMD_slug' => $payment_method_slug]]
490
+		);
491
+		do_action(
492
+			'AHEE__EE_Payment_Method_Manager__deactivate_payment_method__after_deactivating_payment_method',
493
+			$payment_method_slug,
494
+			$count_updated
495
+		);
496
+		return $count_updated;
497
+	}
498
+
499
+
500
+	/**
501
+	 * initializes payment method access caps via EE_Capabilities::init_role_caps()
502
+	 * upon EE_Payment_Method_Manager construction
503
+	 *
504
+	 * @throws EE_Error
505
+	 * @throws DomainException
506
+	 */
507
+	public function initializePaymentMethodCaps()
508
+	{
509
+		// don't do this twice
510
+		if ($this->payment_method_caps_initialized) {
511
+			return;
512
+		}
513
+		EE_Capabilities::instance()->addCaps(
514
+			$this->getPaymentMethodCaps()
515
+		);
516
+		$this->payment_method_caps_initialized = true;
517
+	}
518
+
519
+
520
+	/**
521
+	 * array  of dynamic payment method access caps.
522
+	 * at the time of writing, october 20 2014, these are the caps added:
523
+	 *  ee_payment_method_admin_only
524
+	 *  ee_payment_method_aim
525
+	 *  ee_payment_method_bank
526
+	 *  ee_payment_method_check
527
+	 *  ee_payment_method_invoice
528
+	 *  ee_payment_method_mijireh
529
+	 *  ee_payment_method_paypal_pro
530
+	 *  ee_payment_method_paypal_standard
531
+	 * Any other payment methods added to core or via addons will also get
532
+	 * their related capability automatically added too, so long as they are
533
+	 * registered properly using EE_Register_Payment_Method::register()
534
+	 *
535
+	 * @return array
536
+	 * @throws DomainException
537
+	 */
538
+	protected function getPaymentMethodCaps(): array
539
+	{
540
+		$caps = [];
541
+		foreach ($this->payment_method_type_names() as $payment_method_name) {
542
+			$caps = $this->addPaymentMethodCap($payment_method_name, $caps);
543
+		}
544
+		return $caps;
545
+	}
546
+
547
+
548
+	/**
549
+	 * @param string $payment_method_name
550
+	 * @param array  $payment_method_caps
551
+	 * @param string $role
552
+	 * @return array
553
+	 * @throws DomainException
554
+	 */
555
+	public function addPaymentMethodCap(
556
+		string $payment_method_name,
557
+		array $payment_method_caps,
558
+		string $role = 'administrator'
559
+	): array {
560
+		if (empty($payment_method_name)) {
561
+			throw new DomainException(
562
+				esc_html__(
563
+					'The name of a payment method must be specified to add capabilities.',
564
+					'event_espresso'
565
+				)
566
+			);
567
+		}
568
+		if (empty($role)) {
569
+			throw new DomainException(
570
+				sprintf(
571
+					esc_html__(
572
+						'No role was supplied while trying to add capabilities for the %1$s payment method.',
573
+						'event_espresso'
574
+					),
575
+					$payment_method_name
576
+				)
577
+			);
578
+		}
579
+		if (! isset($payment_method_caps[ $role ])) {
580
+			$payment_method_caps[ $role ] = [];
581
+		}
582
+		$payment_method_caps[ $role ][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX
583
+										  . strtolower($payment_method_name);
584
+		return $payment_method_caps;
585
+	}
586
+
587
+
588
+	/**
589
+	 * callback for FHEE__EE_Capabilities__init_role_caps__caps_map filter
590
+	 * to add dynamic payment method access caps when capabilities are reset
591
+	 * (or if that filter is called and PM caps are not already set)
592
+	 *
593
+	 * @param array $caps capabilities being filtered
594
+	 * @param bool  $reset
595
+	 * @return array
596
+	 * @throws DomainException
597
+	 */
598
+	public function addPaymentMethodCapsDuringReset(array $caps, bool $reset = false): array
599
+	{
600
+		if ($reset || ! $this->payment_method_caps_initialized) {
601
+			$this->payment_method_caps_initialized = true;
602
+			$caps                                  = array_merge_recursive($caps, $this->getPaymentMethodCaps());
603
+		}
604
+		return $caps;
605
+	}
606
+
607
+
608
+	/**
609
+	 * @param $caps
610
+	 * @return mixed
611
+	 * @deprecated 4.9.42
612
+	 */
613
+	public function add_payment_method_caps($caps)
614
+	{
615
+		return $caps;
616
+	}
617 617
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
     public static function instance(): EE_Payment_Method_Manager
76 76
     {
77 77
         // check if class object is instantiated, and instantiated properly
78
-        if (! self::$_instance instanceof EE_Payment_Method_Manager) {
78
+        if ( ! self::$_instance instanceof EE_Payment_Method_Manager) {
79 79
             EE_Registry::instance()->load_lib('PMT_Base');
80 80
             self::$_instance = new self();
81 81
         }
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function maybe_register_payment_methods(bool $force_recheck = false)
130 130
     {
131
-        if (! $this->_payment_method_types || $force_recheck) {
131
+        if ( ! $this->_payment_method_types || $force_recheck) {
132 132
             $this->_register_payment_methods();
133 133
         }
134 134
     }
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
     protected function _register_payment_methods(): array
143 143
     {
144 144
         // grab list of installed modules
145
-        $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
145
+        $pm_to_register = glob(EE_PAYMENT_METHODS.'*', GLOB_ONLYDIR);
146 146
         // filter list of modules to register
147 147
         $pm_to_register = apply_filters(
148 148
             'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
@@ -185,9 +185,9 @@  discard block
 block discarded – undo
185 185
         // create class name from module directory name
186 186
         $module = str_replace(['_', ' '], [' ', '_'], $module_dir);
187 187
         // add class prefix
188
-        $module_class = 'EE_PMT_' . $module;
188
+        $module_class = 'EE_PMT_'.$module;
189 189
         // does the module exist ?
190
-        if (! is_readable($payment_method_path . '/' . $module_class . $module_ext)) {
190
+        if ( ! is_readable($payment_method_path.'/'.$module_class.$module_ext)) {
191 191
             $msg = sprintf(
192 192
                 esc_html__(
193 193
                     'The requested %s payment method file could not be found or is not readable due to file permissions.',
@@ -195,22 +195,22 @@  discard block
 block discarded – undo
195 195
                 ),
196 196
                 $module
197 197
             );
198
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
198
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
199 199
             return false;
200 200
         }
201 201
         // load the module class file
202
-        require_once($payment_method_path . '/' . $module_class . $module_ext);
202
+        require_once($payment_method_path.'/'.$module_class.$module_ext);
203 203
         // verify that class exists
204
-        if (! class_exists($module_class)) {
204
+        if ( ! class_exists($module_class)) {
205 205
             $msg = sprintf(
206 206
                 esc_html__('The requested %s module class does not exist.', 'event_espresso'),
207 207
                 $module_class
208 208
             );
209
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
209
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
210 210
             return false;
211 211
         }
212 212
         // add to array of registered modules
213
-        $this->_payment_method_types[ $module ] = $payment_method_path . '/' . $module_class . $module_ext;
213
+        $this->_payment_method_types[$module] = $payment_method_path.'/'.$module_class.$module_ext;
214 214
         return true;
215 215
     }
216 216
 
@@ -227,12 +227,12 @@  discard block
 block discarded – undo
227 227
         if (
228 228
             $force_recheck
229 229
             || empty($this->_payment_method_types)
230
-            || ! isset($this->_payment_method_types[ $payment_method_name ])
230
+            || ! isset($this->_payment_method_types[$payment_method_name])
231 231
         ) {
232 232
             $this->maybe_register_payment_methods($force_recheck);
233 233
         }
234
-        if (isset($this->_payment_method_types[ $payment_method_name ])) {
235
-            require_once($this->_payment_method_types[ $payment_method_name ]);
234
+        if (isset($this->_payment_method_types[$payment_method_name])) {
235
+            require_once($this->_payment_method_types[$payment_method_name]);
236 236
             return true;
237 237
         }
238 238
         return false;
@@ -274,8 +274,8 @@  discard block
 block discarded – undo
274 274
         if ($force_recheck || empty($this->payment_method_objects)) {
275 275
             $this->maybe_register_payment_methods($force_recheck);
276 276
             foreach ($this->payment_method_type_names(true) as $classname) {
277
-                if (! isset($this->payment_method_objects[ $classname ])) {
278
-                    $this->payment_method_objects[ $classname ] = new $classname();
277
+                if ( ! isset($this->payment_method_objects[$classname])) {
278
+                    $this->payment_method_objects[$classname] = new $classname();
279 279
                 }
280 280
             }
281 281
         }
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
      */
305 305
     public function payment_method_class_from_type(string $type): string
306 306
     {
307
-        return 'EE_PMT_' . $type;
307
+        return 'EE_PMT_'.$type;
308 308
     }
309 309
 
310 310
 
@@ -321,13 +321,13 @@  discard block
 block discarded – undo
321 321
     {
322 322
         $this->maybe_register_payment_methods();
323 323
         $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
324
-        if (! $payment_method instanceof EE_Payment_Method) {
324
+        if ( ! $payment_method instanceof EE_Payment_Method) {
325 325
             $pm_type_class = $this->payment_method_class_from_type($payment_method_type);
326 326
             if (class_exists($pm_type_class)) {
327 327
                 /** @var $pm_type_obj EE_PMT_Base */
328 328
                 $pm_type_obj    = new $pm_type_class();
329 329
                 $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
330
-                if (! $payment_method) {
330
+                if ( ! $payment_method) {
331 331
                     $payment_method = $this->create_payment_method_of_type($pm_type_obj);
332 332
                 }
333 333
                 $payment_method->set_type($payment_method_type);
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
         $payment_method->save();
349 349
 
350 350
         // delete any auto-deactivation notices that may have been set
351
-        PersistentAdminNoticeManager::deletePersistentAdminNotice('auto-deactivated-' . $payment_method->slug());
351
+        PersistentAdminNoticeManager::deletePersistentAdminNotice('auto-deactivated-'.$payment_method->slug());
352 352
 
353 353
         /** @type EE_Message_Resource_Manager $message_resource_manager */
354 354
         // if this was the invoice message type, make sure users can view their invoices
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
                         'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.',
369 369
                         'event_espresso'
370 370
                     ),
371
-                    '<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">',
371
+                    '<a href="'.admin_url('admin.php?page=espresso_messages&action=settings').'">',
372 372
                     '</a>'
373 373
                 ),
374 374
                 true
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
                 'PMD_type'       => $pm_type_obj->system_name(),
402 402
                 'PMD_name'       => $pm_type_obj->defaultFrontendName(),
403 403
                 'PMD_admin_name' => $pm_type_obj->pretty_name(),
404
-                'PMD_slug'       => $pm_type_obj->system_name(),// automatically converted to slug
404
+                'PMD_slug'       => $pm_type_obj->system_name(), // automatically converted to slug
405 405
                 'PMD_wp_user'    => $current_user->ID,
406 406
                 'PMD_order'      => EEM_Payment_Method::instance()->count(
407 407
                     [['PMD_type' => ['!=', 'Admin_Only']]]
@@ -423,14 +423,14 @@  discard block
 block discarded – undo
423 423
     {
424 424
         $pm_type_obj = $payment_method->type_obj();
425 425
         $payment_method->set_description($pm_type_obj->default_description());
426
-        if (! $payment_method->button_url()) {
426
+        if ( ! $payment_method->button_url()) {
427 427
             $payment_method->set_button_url($pm_type_obj->default_button_url());
428 428
         }
429 429
         // now add setup its default extra meta properties
430 430
         $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
431
-        if (! empty($extra_metas)) {
431
+        if ( ! empty($extra_metas)) {
432 432
             // verify the payment method has an ID before adding extra meta
433
-            if (! $payment_method->ID()) {
433
+            if ( ! $payment_method->ID()) {
434 434
                 $payment_method->save();
435 435
             }
436 436
             foreach ($extra_metas as $meta_name => $input) {
@@ -576,10 +576,10 @@  discard block
 block discarded – undo
576 576
                 )
577 577
             );
578 578
         }
579
-        if (! isset($payment_method_caps[ $role ])) {
580
-            $payment_method_caps[ $role ] = [];
579
+        if ( ! isset($payment_method_caps[$role])) {
580
+            $payment_method_caps[$role] = [];
581 581
         }
582
-        $payment_method_caps[ $role ][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX
582
+        $payment_method_caps[$role][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX
583 583
                                           . strtolower($payment_method_name);
584 584
         return $payment_method_caps;
585 585
     }
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_PMT_Base.lib.php 2 patches
Indentation   +926 added lines, -926 removed lines patch added patch discarded remove patch
@@ -16,930 +16,930 @@
 block discarded – undo
16 16
  */
17 17
 abstract class EE_PMT_Base
18 18
 {
19
-    const onsite  = 'on-site';
20
-
21
-    const offsite = 'off-site';
22
-
23
-    const offline = 'off-line';
24
-
25
-    protected ?EE_Payment_Method $_pm_instance = null;
26
-
27
-    protected ?EE_Gateway $_gateway = null;
28
-
29
-    protected ?EE_Payment_Method_Form $_settings_form = null;
30
-
31
-    protected ?EE_Form_Section_Proper $_billing_form = null;
32
-
33
-    protected bool $_cache_billing_form = true;
34
-
35
-    protected ?bool $_has_billing_form;
36
-
37
-    protected bool $_requires_https = false;
38
-
39
-    /**
40
-     * String of the absolute path to the folder containing this file, with a trailing slash.
41
-     * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/'
42
-     *
43
-     * @var string|null
44
-     */
45
-    protected $_file_folder = null;
46
-
47
-    /**
48
-     * String to the absolute URL to this file (useful for getting its web-accessible resources
49
-     * like images, js, or css)
50
-     *
51
-     * @var string|null
52
-     */
53
-    protected $_file_url = null;
54
-
55
-    /**
56
-     * Pretty name for the payment method
57
-     *
58
-     * @var string|null
59
-     */
60
-    protected $_pretty_name = null;
61
-
62
-    /**
63
-     * @var string|null
64
-     */
65
-    protected $_default_button_url = null;
66
-
67
-    /**
68
-     * @var string|null
69
-     */
70
-    protected $_default_description = null;
71
-
72
-    /**
73
-     * @var string|null
74
-     */
75
-    protected $_template_path = null;
76
-
77
-
78
-    /**
79
-     * @param EE_Payment_Method|null $pm_instance
80
-     * @throws ReflectionException
81
-     * @throws EE_Error
82
-     */
83
-    public function __construct($pm_instance = null)
84
-    {
85
-        if ($pm_instance instanceof EE_Payment_Method) {
86
-            $this->set_instance($pm_instance);
87
-        }
88
-        if ($this->_gateway) {
89
-            $this->_gateway->set_payment_model(EEM_Payment::instance());
90
-            $this->_gateway->set_payment_log(EEM_Change_Log::instance());
91
-            $this->_gateway->set_template_helper(new EEH_Template());
92
-            $this->_gateway->set_line_item_helper(new EEH_Line_Item());
93
-            $this->_gateway->set_money_helper(new EEH_Money());
94
-            $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
95
-            $this->_gateway->set_unsupported_character_remover(new AsciiOnly());
96
-            do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
97
-        }
98
-        if (! isset($this->_has_billing_form)) {
99
-            // by default, On Site gateways have a billing form
100
-            if ($this->payment_occurs() == EE_PMT_Base::onsite) {
101
-                $this->set_has_billing_form(true);
102
-            } else {
103
-                $this->set_has_billing_form(false);
104
-            }
105
-        }
106
-
107
-        if (! $this->_pretty_name) {
108
-            throw new EE_Error(
109
-                esc_html__(
110
-                    'You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized',
111
-                    'event_espresso'
112
-                )
113
-            );
114
-        }
115
-        // if the child didn't specify a default button, use the credit card one
116
-        if ($this->_default_button_url === null) {
117
-            $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods/pay-by-credit-card.png';
118
-        }
119
-    }
120
-
121
-
122
-    /**
123
-     * @param bool|int|string $has_billing_form
124
-     */
125
-    public function set_has_billing_form($has_billing_form)
126
-    {
127
-        $this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN);
128
-    }
129
-
130
-
131
-    /**
132
-     * sets the file_folder property
133
-     */
134
-    protected function _set_file_folder()
135
-    {
136
-        $reflector          = new ReflectionClass(get_class($this));
137
-        $fn                 = $reflector->getFileName();
138
-        $this->_file_folder = dirname($fn) . '/';
139
-    }
140
-
141
-
142
-    /**
143
-     * sets the file URL with a trailing slash for this PMT
144
-     */
145
-    protected function _set_file_url()
146
-    {
147
-        $plugins_dir_fixed = str_replace('\\', '/', WP_PLUGIN_DIR);
148
-        $file_folder_fixed = str_replace('\\', '/', $this->file_folder());
149
-        $file_path         = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed);
150
-        $this->_file_url   = set_url_scheme($file_path);
151
-    }
152
-
153
-
154
-    /**
155
-     * Gets the default description on all payment methods of this type
156
-     *
157
-     * @return string
158
-     */
159
-    public function default_description(): ?string
160
-    {
161
-        return $this->_default_description;
162
-    }
163
-
164
-
165
-    /**
166
-     * Returns the folder containing the PMT child class, with a trailing slash
167
-     *
168
-     * @return string
169
-     */
170
-    public function file_folder(): ?string
171
-    {
172
-        if (! $this->_file_folder) {
173
-            $this->_set_file_folder();
174
-        }
175
-        return $this->_file_folder;
176
-    }
177
-
178
-
179
-    /**
180
-     * @return string
181
-     */
182
-    public function file_url(): ?string
183
-    {
184
-        if (! $this->_file_url) {
185
-            $this->_set_file_url();
186
-        }
187
-        return $this->_file_url;
188
-    }
189
-
190
-
191
-    /**
192
-     * Sets the payment method instance this payment method type is for.
193
-     * Its important teh payment method instance is set before
194
-     *
195
-     * @param EE_Payment_Method $payment_method_instance
196
-     * @throws EE_Error
197
-     * @throws ReflectionException
198
-     */
199
-    public function set_instance(EE_Payment_Method $payment_method_instance)
200
-    {
201
-        $this->_pm_instance = $payment_method_instance;
202
-        // if they have already requested the settings form, make sure its
203
-        // data matches this model object
204
-        if ($this->_settings_form) {
205
-            $this->settings_form()->populate_model_obj($payment_method_instance);
206
-        }
207
-        if ($this->_gateway instanceof EE_Gateway) {
208
-            $this->_gateway->set_settings($payment_method_instance->settings_array());
209
-        }
210
-    }
211
-
212
-
213
-    /**
214
-     * Gets teh form for displaying to admins where they set up the payment method
215
-     *
216
-     * @return EE_Payment_Method_Form
217
-     * @throws EE_Error
218
-     * @throws ReflectionException
219
-     */
220
-    public function settings_form(): EE_Payment_Method_Form
221
-    {
222
-        if (! $this->_settings_form) {
223
-            $this->_settings_form = $this->generate_new_settings_form();
224
-            $this->_settings_form->set_payment_method_type($this);
225
-            // if we have already assigned a model object to this pmt, make
226
-            // sure it's reflected in the form we just generated
227
-            if ($this->_pm_instance) {
228
-                $this->_settings_form->populate_model_obj($this->_pm_instance);
229
-            }
230
-        }
231
-        return $this->_settings_form;
232
-    }
233
-
234
-
235
-    /**
236
-     * Gets the form for all the settings related to this payment method type
237
-     *
238
-     * @return EE_Payment_Method_Form
239
-     */
240
-    abstract public function generate_new_settings_form();
241
-
242
-
243
-    /**
244
-     * Sets the form for settings. This may be useful if we have already received
245
-     * a form submission and have form data it in, and want to use it anytime we're showing
246
-     * this payment method type's settings form later in the request
247
-     *
248
-     * @param EE_Payment_Method_Form $form
249
-     */
250
-    public function set_settings_form(EE_Payment_Method_Form $form)
251
-    {
252
-        $this->_settings_form = $form;
253
-    }
254
-
255
-
256
-    /**
257
-     * @return boolean
258
-     */
259
-    public function has_billing_form(): bool
260
-    {
261
-        return $this->_has_billing_form;
262
-    }
263
-
264
-
265
-    /**
266
-     * Gets the form for displaying to attendees where they can enter their billing info
267
-     * which will be sent to teh gateway (can be null)
268
-     *
269
-     * @param EE_Transaction|null $transaction
270
-     * @param array               $extra_args
271
-     * @return EE_Billing_Attendee_Info_Form|EE_Billing_Info_Form|null
272
-     * @throws EE_Error
273
-     * @throws ReflectionException
274
-     */
275
-    public function billing_form(EE_Transaction $transaction = null, array $extra_args = [])
276
-    {
277
-        // has billing form already been regenerated ? or overwrite cache?
278
-        if (! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) {
279
-            $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
280
-        }
281
-        // if we know who the attendee is, and this is a billing form
282
-        // that uses attendee info, populate it
283
-        if (
284
-            apply_filters(
285
-                'FHEE__populate_billing_form_fields_from_attendee',
286
-                (
287
-                    $this->_billing_form instanceof EE_Billing_Attendee_Info_Form
288
-                    && $transaction instanceof EE_Transaction
289
-                    && $transaction->primary_registration() instanceof EE_Registration
290
-                    && $transaction->primary_registration()->attendee() instanceof EE_Attendee
291
-                ),
292
-                $this->_billing_form,
293
-                $transaction
294
-            )
295
-        ) {
296
-            $this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee());
297
-        }
298
-        return $this->_billing_form;
299
-    }
300
-
301
-
302
-    /**
303
-     * Creates the billing form for this payment method type
304
-     *
305
-     * @param EE_Transaction|null $transaction
306
-     * @return EE_Billing_Info_Form|null
307
-     */
308
-    abstract public function generate_new_billing_form(EE_Transaction $transaction = null);
309
-
310
-
311
-    /**
312
-     * applies debug data to the form
313
-     *
314
-     * @param EE_Billing_Info_Form $billing_form
315
-     * @return EE_Billing_Info_Form|null
316
-     */
317
-    public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form)
318
-    {
319
-        return $billing_form;
320
-    }
321
-
322
-
323
-    /**
324
-     * Sets the billing form for this payment method type. You may want to use this
325
-     * if you have form
326
-     *
327
-     * @param EE_Billing_Info_Form $form
328
-     */
329
-    public function set_billing_form(EE_Billing_Info_Form $form)
330
-    {
331
-        $this->_billing_form = $form;
332
-    }
333
-
334
-
335
-    /**
336
-     * Returns whether this payment method requires HTTPS to be used
337
-     *
338
-     * @return boolean
339
-     */
340
-    public function requires_https(): bool
341
-    {
342
-        return $this->_requires_https;
343
-    }
344
-
345
-
346
-    /**
347
-     * @param EE_Transaction            $transaction
348
-     * @param float|null                $amount
349
-     * @param EE_Billing_Info_Form|null $billing_info
350
-     * @param string|null               $return_url
351
-     * @param string                    $fail_url
352
-     * @param string                    $method
353
-     * @param bool                      $by_admin
354
-     * @return EE_Payment
355
-     * @throws EE_Error
356
-     * @throws ReflectionException
357
-     */
358
-    public function process_payment(
359
-        EE_Transaction $transaction,
360
-        $amount = null,
361
-        $billing_info = null,
362
-        $return_url = null,
363
-        $fail_url = '',
364
-        $method = EEM_Payment_Method::scope_cart,
365
-        $by_admin = false
366
-    ) {
367
-        $amount = $amount ?: $transaction->remaining();
368
-        $method = EEM_Payment_Method::instance()->is_valid_scope($method) ? $method : EEM_Payment_Method::scope_cart;
369
-
370
-        // if there is billing info, clean it and save it NOW before doing anything else
371
-        if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
372
-            $this->_save_billing_info_to_attendee($billing_info, $transaction);
373
-        }
374
-
375
-        // @todo: add surcharge for the payment method, if any
376
-        if (! $this->_gateway instanceof EE_Gateway) {
377
-            // no gateway provided
378
-            // there is no payment. Must be an offline gateway
379
-            // create a payment object anyways, but don't save it
380
-            return EE_Payment::new_instance(
381
-                [
382
-                    'STS_ID'        => EEM_Payment::status_id_pending,
383
-                    'TXN_ID'        => $transaction->ID(),
384
-                    'PMD_ID'        => $transaction->payment_method_ID(),
385
-                    'PAY_amount'    => 0.00,
386
-                    'PAY_timestamp' => time(),
387
-                ]
388
-            );
389
-        }
390
-
391
-        $payment = $this->getLastPayment($transaction, $amount, $method);
392
-        $payment = $this->validatePayment($transaction, $payment, $amount, $method);
393
-
394
-        $max_payment_attempts   = apply_filters(
395
-            'FHEE__EE_PMT_Base__process_payment__max_payment_attempts',
396
-            5,
397
-            $transaction
398
-        );
399
-        $previous_payment_count = $this->getPreviousPaymentCount($transaction, $amount, $method);
400
-        if ($previous_payment_count >= $max_payment_attempts) {
401
-            return $payment;
402
-        }
403
-
404
-        return $this->passPaymentToGateway($payment, $transaction, $billing_info, $return_url, $fail_url);
405
-    }
406
-
407
-
408
-    /**
409
-     * Checks for any existing payments that are in a failed state for the same TXN, amount, and method
410
-     *
411
-     * @param EE_Transaction $transaction
412
-     * @param float          $amount
413
-     * @param string         $method
414
-     * @return EE_Payment|null
415
-     * @throws EE_Error
416
-     * @throws ReflectionException
417
-     * @since 5.0.28.p
418
-     */
419
-    private function getLastPayment(EE_Transaction $transaction, float $amount, string $method): ?EE_Payment
420
-    {
421
-        return EEM_Payment::instance()->get_one(
422
-            [
423
-                [
424
-                    'STS_ID'     => EEM_Payment::status_id_failed,
425
-                    'TXN_ID'     => $transaction->ID(),
426
-                    'PMD_ID'     => $this->_pm_instance->ID(),
427
-                    'PAY_source' => $method,
428
-                    'PAY_amount' => $amount,
429
-                ],
430
-            ]
431
-        );
432
-    }
433
-
434
-
435
-    /**
436
-     * IF the last payment was not a failed payment
437
-     * (which indicates a payment in progress that has yet to be updated),
438
-     * then create a new payment, otherwise just return the existing payment,
439
-     * but save it to ensure it has an ID
440
-     *
441
-     * @param EE_Transaction  $transaction
442
-     * @param EE_Payment|null $payment
443
-     * @param float           $amount
444
-     * @param string          $method
445
-     * @return EE_Payment
446
-     * @throws EE_Error
447
-     * @throws ReflectionException
448
-     * @since 5.0.28.p
449
-     */
450
-    private function validatePayment(
451
-        EE_Transaction $transaction,
452
-        ?EE_Payment $payment,
453
-        float $amount,
454
-        string $method
455
-    ): EE_Payment {
456
-        if (! $payment instanceof EE_Payment || ! $payment->is_failed()) {
457
-            $payment = EE_Payment::new_instance(
458
-                [
459
-                    'PAY_amount'           => $amount,
460
-                    'PAY_details'          => null,
461
-                    'PAY_extra_accntng'    => null,
462
-                    'PAY_gateway_response' => null,
463
-                    'PAY_po_number'        => null,
464
-                    'PAY_source'           => $method,
465
-                    'PAY_timestamp'        => time(),
466
-                    'PAY_txn_id_chq_nmbr'  => null,
467
-                    'PMD_ID'               => $this->_pm_instance->ID(),
468
-                    'STS_ID'               => EEM_Payment::status_id_failed,
469
-                    'TXN_ID'               => $transaction->ID(),
470
-                ]
471
-            );
472
-        }
473
-        // make sure the payment has been saved to show we started it,
474
-        // and so it has an ID should the gateway try to log it
475
-        $payment->save();
476
-
477
-        return $payment;
478
-    }
479
-
480
-
481
-    /**
482
-     * Checks for any existing payments that are in a failed state for the same TXN, amount, and method
483
-     *
484
-     * @param EE_Transaction $transaction
485
-     * @param float          $amount
486
-     * @param string         $method
487
-     * @return int
488
-     * @throws EE_Error
489
-     * @throws ReflectionException
490
-     * @since 5.0.28.p
491
-     */
492
-    private function getPreviousPaymentCount(EE_Transaction $transaction, float $amount, string $method): int
493
-    {
494
-        return EEM_Payment::instance()->count(
495
-            [
496
-                [
497
-                    'STS_ID'     => [
498
-                        'IN',
499
-                        [
500
-                            EEM_Payment::status_id_pending,
501
-                            EEM_Payment::status_id_cancelled,
502
-                            EEM_Payment::status_id_declined,
503
-                            EEM_Payment::status_id_failed,
504
-                        ],
505
-                    ],
506
-                    'TXN_ID'     => $transaction->ID(),
507
-                    'PMD_ID'     => $this->_pm_instance->ID(),
508
-                    'PAY_source' => $method,
509
-                    'PAY_amount' => $amount,
510
-                ],
511
-                'order_by' => ['PAY_timestamp' => 'DESC'],
512
-            ]
513
-        );
514
-    }
515
-
516
-
517
-    /**
518
-     * @param EE_Payment                $payment
519
-     * @param EE_Transaction            $transaction
520
-     * @param EE_Billing_Info_Form|null $billing_info
521
-     * @param string|null               $return_url
522
-     * @param string|null               $fail_url
523
-     * @return EE_Payment
524
-     * @throws EE_Error
525
-     * @throws ReflectionException
526
-     * @since 5.0.28.p
527
-     */
528
-    private function passPaymentToGateway(
529
-        EE_Payment $payment,
530
-        EE_Transaction $transaction,
531
-        ?EE_Billing_Info_Form $billing_info,
532
-        ?string $return_url = null,
533
-        ?string $fail_url = ''
534
-    ): EE_Payment {
535
-        $billing_values = $this->_get_billing_values_from_form($billing_info);
536
-        if ($this->_gateway instanceof EE_Offsite_Gateway) {
537
-            $payment = $this->_gateway->set_redirection_info(
538
-                $payment,
539
-                $billing_values,
540
-                $return_url,
541
-                EE_Config::instance()->core->txn_page_url(
542
-                    [
543
-                        'e_reg_url_link'    => $transaction->primary_registration()->reg_url_link(),
544
-                        'ee_payment_method' => $this->_pm_instance->slug(),
545
-                    ]
546
-                ),
547
-                $fail_url
548
-            );
549
-            $payment->save();
550
-        } elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
551
-            $payment = $this->_gateway->do_direct_payment($payment, $billing_values);
552
-            $payment->save();
553
-        } else {
554
-            throw new EE_Error(
555
-                sprintf(
556
-                    esc_html__(
557
-                        'Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)',
558
-                        'event_espresso'
559
-                    ),
560
-                    get_class($this),
561
-                    gettype($this->_gateway)
562
-                )
563
-            );
564
-        }
565
-        return $payment;
566
-    }
567
-
568
-
569
-    /**
570
-     * Gets the values we want to pass onto the gateway. Normally these
571
-     * are just the 'pretty' values, but there may be times the data may need
572
-     * a  little massaging. Proper subsections will become arrays of inputs
573
-     *
574
-     * @param EE_Billing_Info_Form|null $billing_form
575
-     * @return array
576
-     * @throws EE_Error
577
-     */
578
-    protected function _get_billing_values_from_form($billing_form)
579
-    {
580
-        return $billing_form instanceof EE_Form_Section_Proper
581
-            ? $billing_form->input_pretty_values(true)
582
-            : [];
583
-    }
584
-
585
-
586
-    /**
587
-     * Handles an instant payment notification when the transaction is known (by default).
588
-     *
589
-     * @param array          $req_data
590
-     * @param EE_Transaction $transaction
591
-     * @return EE_Payment
592
-     * @throws EE_Error
593
-     * @throws ReflectionException
594
-     */
595
-    public function handle_ipn(array $req_data, EE_Transaction $transaction): EE_Payment
596
-    {
597
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
598
-        if (! $this->_gateway instanceof EE_Offsite_Gateway) {
599
-            throw new EE_Error(
600
-                sprintf(
601
-                    esc_html__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"),
602
-                    print_r($this->_gateway, true)
603
-                )
604
-            );
605
-        }
606
-        return $this->_gateway->handle_payment_update($req_data, $transaction);
607
-    }
608
-
609
-
610
-    /**
611
-     * Saves the billing info onto the attendee of the primary registrant on this transaction, and
612
-     * cleans it first.
613
-     *
614
-     * @param EE_Billing_Attendee_Info_Form $billing_form
615
-     * @param EE_Transaction|null           $transaction
616
-     * @return boolean success
617
-     * @throws EE_Error
618
-     * @throws ReflectionException
619
-     */
620
-    protected function _save_billing_info_to_attendee(
621
-        EE_Billing_Attendee_Info_Form $billing_form,
622
-        ?EE_Transaction $transaction
623
-    ): bool {
624
-        if (! $transaction instanceof EE_Transaction) {
625
-            EE_Error::add_error(
626
-                esc_html__("Cannot save billing info because no transaction was specified", "event_espresso"),
627
-                __FILE__,
628
-                __FUNCTION__,
629
-                __LINE__
630
-            );
631
-            return false;
632
-        }
633
-        $primary_reg = $transaction->primary_registration();
634
-        if (! $primary_reg) {
635
-            EE_Error::add_error(
636
-                esc_html__(
637
-                    "Cannot save billing info because the transaction has no primary registration",
638
-                    "event_espresso"
639
-                ),
640
-                __FILE__,
641
-                __FUNCTION__,
642
-                __LINE__
643
-            );
644
-            return false;
645
-        }
646
-        $attendee = $primary_reg->attendee();
647
-        if (! $attendee) {
648
-            EE_Error::add_error(
649
-                esc_html__(
650
-                    "Cannot save billing info because the transaction's primary registration has no attendee!",
651
-                    "event_espresso"
652
-                ),
653
-                __FILE__,
654
-                __FUNCTION__,
655
-                __LINE__
656
-            );
657
-            return false;
658
-        }
659
-        return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
660
-    }
661
-
662
-
663
-    /**
664
-     * Gets the payment this IPN is for. Children may often want to
665
-     * override this to inspect the request
666
-     *
667
-     * @param EE_Transaction $transaction
668
-     * @param array          $req_data
669
-     * @return EE_Payment
670
-     * @throws EE_Error
671
-     * @throws ReflectionException
672
-     */
673
-    protected function find_payment_for_ipn(EE_Transaction $transaction, array $req_data = []): EE_Payment
674
-    {
675
-        return $transaction->last_payment();
676
-    }
677
-
678
-
679
-    /**
680
-     * In case generic code cannot provide the payment processor with a specific payment method
681
-     * and transaction, it will try calling this method on each activate payment method.
682
-     * If the payment method is able to identify the request as being for it, it should fetch
683
-     * the payment it's for and return it. If not, it should throw an EE_Error to indicate it cannot
684
-     * handle the IPN
685
-     *
686
-     * @param array $req_data
687
-     * @return EE_Payment only if this payment method can find the info its needs from $req_data
688
-     * and identifies the IPN as being for this payment method (not just fo ra payment method of this type)
689
-     * @throws EE_Error
690
-     */
691
-    public function handle_unclaimed_ipn(array $req_data = []): EE_Payment
692
-    {
693
-        throw new EE_Error(
694
-            sprintf(
695
-                esc_html__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"),
696
-                get_class($this)
697
-            )
698
-        );
699
-    }
700
-
701
-
702
-    /**
703
-     * Logic to be accomplished when the payment attempt is complete.
704
-     * Most payment methods don't need to do anything at this point; but some, like Mijireh, do.
705
-     * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from
706
-     * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status
707
-     * of the payment). Fed a transaction because it's always assumed to be the last payment that
708
-     * we're dealing with. Returns that last payment (if there is one)
709
-     *
710
-     * @param EE_Transaction $transaction
711
-     * @return EE_Payment|null
712
-     * @throws EE_Error
713
-     * @throws ReflectionException
714
-     */
715
-    public function finalize_payment_for(EE_Transaction $transaction): ?EE_Payment
716
-    {
717
-        return $transaction->last_payment();
718
-    }
719
-
720
-
721
-    /**
722
-     * Whether this payment method's gateway supports sending refund requests
723
-     *
724
-     * @return boolean
725
-     */
726
-    public function supports_sending_refunds(): bool
727
-    {
728
-        return $this->_gateway instanceof EE_Gateway && $this->_gateway->supports_sending_refunds();
729
-    }
730
-
731
-
732
-    /**
733
-     * @param EE_Payment $payment
734
-     * @param array      $refund_info
735
-     * @return EE_Payment
736
-     * @throws EE_Error
737
-     */
738
-    public function process_refund(EE_Payment $payment, array $refund_info = []): EE_Payment
739
-    {
740
-        if ($this->_gateway instanceof EE_Gateway) {
741
-            return $this->_gateway->do_direct_refund($payment, $refund_info);
742
-        } else {
743
-            throw new EE_Error(
744
-                sprintf(
745
-                    esc_html__('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'),
746
-                    get_class($this)
747
-                )
748
-            );
749
-        }
750
-    }
751
-
752
-
753
-    /**
754
-     * Returns one the class's constants onsite,offsite, or offline, depending on this
755
-     * payment method's gateway.
756
-     *
757
-     * @return string
758
-     * @throws EE_Error
759
-     */
760
-    public function payment_occurs(): string
761
-    {
762
-        if (! $this->_gateway) {
763
-            return EE_PMT_Base::offline;
764
-        }
765
-        if ($this->_gateway instanceof EE_Onsite_Gateway) {
766
-            return EE_PMT_Base::onsite;
767
-        }
768
-        if ($this->_gateway instanceof EE_Offsite_Gateway) {
769
-            return EE_PMT_Base::offsite;
770
-        }
771
-        throw new EE_Error(
772
-            sprintf(
773
-                esc_html__(
774
-                    "Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those",
775
-                    "event_espresso"
776
-                ),
777
-                get_class($this)
778
-            )
779
-        );
780
-    }
781
-
782
-
783
-    /**
784
-     * For adding any html output ab ove the payment overview.
785
-     * Many gateways won't want ot display anything, so this function just returns an empty string.
786
-     * Other gateways may want to override this, such as offline gateways.
787
-     *
788
-     * @param EE_Payment $payment
789
-     * @return string
790
-     */
791
-    public function payment_overview_content(EE_Payment $payment)
792
-    {
793
-        return EEH_Template::display_template(
794
-            EE_LIBRARIES . 'payment_methods/templates/payment_details_content.template.php',
795
-            ['payment_method' => $this->_pm_instance, 'payment' => $payment],
796
-            true
797
-        );
798
-    }
799
-
800
-
801
-    /**
802
-     * @return array where keys are the help tab name,
803
-     * values are: array {
804
-     * @type string $title         i18n name for the help tab
805
-     * @type string $filename      name of the file located in ./help_tabs/ (ie, in a folder next to this file)
806
-     * @type array  $template_args any arguments you want passed to the template file while rendering.
807
-     *                             Keys will be variable names and values with be their values.
808
-     */
809
-    public function help_tabs_config()
810
-    {
811
-        return [];
812
-    }
813
-
814
-
815
-    /**
816
-     * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into
817
-     * the payment method's table's PMT_type column)
818
-     *
819
-     * @return string
820
-     */
821
-    public function system_name()
822
-    {
823
-        $classname = get_class($this);
824
-        return str_replace("EE_PMT_", '', $classname);
825
-    }
826
-
827
-
828
-    /**
829
-     * A pretty i18n version of the PMT name. Often the same as the "pretty_name", but you can change it by overriding
830
-     * this method.
831
-     *
832
-     * @return string|null
833
-     */
834
-    public function defaultFrontendName()
835
-    {
836
-        return $this->pretty_name();
837
-    }
838
-
839
-
840
-    /**
841
-     * A pretty i18n version of the PMT name
842
-     *
843
-     * @return string|null
844
-     */
845
-    public function pretty_name(): ?string
846
-    {
847
-        return $this->_pretty_name;
848
-    }
849
-
850
-
851
-    /**
852
-     * Gets the default absolute URL to the payment method type's button
853
-     *
854
-     * @return string|null
855
-     */
856
-    public function default_button_url(): ?string
857
-    {
858
-        return $this->_default_button_url;
859
-    }
860
-
861
-
862
-    /**
863
-     * Gets the gateway used by this payment method (if any)
864
-     *
865
-     * @return EE_Gateway
866
-     */
867
-    public function get_gateway(): ?EE_Gateway
868
-    {
869
-        return $this->_gateway;
870
-    }
871
-
872
-
873
-    /**
874
-     * @return string html for the link to a help tab
875
-     */
876
-    public function get_help_tab_link(): string
877
-    {
878
-        return EEH_Template::get_help_tab_link(
879
-            $this->get_help_tab_name(),
880
-            'espresso_payment_settings',
881
-            'default'
882
-        );
883
-    }
884
-
885
-
886
-    /**
887
-     * Returns the name of the help tab for this PMT
888
-     *
889
-     * @return string
890
-     */
891
-    public function get_help_tab_name(): string
892
-    {
893
-        return 'ee_' . strtolower($this->system_name()) . '_help_tab';
894
-    }
895
-
896
-
897
-    /**
898
-     * The name of the wp capability that should be associated with the usage of
899
-     * this PMT by an admin
900
-     *
901
-     * @return string
902
-     */
903
-    public function cap_name(): string
904
-    {
905
-        return 'ee_payment_method_' . strtolower($this->system_name());
906
-    }
907
-
908
-
909
-    /**
910
-     * Called by client code to tell the gateway that if it wants to change
911
-     * the transaction or line items or registrations related to teh payment it already
912
-     * processed (we think, but possibly not) that now's the time to do it.
913
-     * It is expected that gateways will store any info they need for this on the PAY_details,
914
-     * or maybe an extra meta value
915
-     *
916
-     * @param EE_Payment $payment
917
-     * @return void
918
-     */
919
-    public function update_txn_based_on_payment($payment)
920
-    {
921
-        if ($this->_gateway instanceof EE_Gateway) {
922
-            $this->_gateway->update_txn_based_on_payment($payment);
923
-        }
924
-    }
925
-
926
-
927
-    /**
928
-     * Returns a string of HTML describing this payment method type for an admin,
929
-     * primarily intended for them to read before activating it.
930
-     * The easiest way to set this is to create a folder 'templates' alongside
931
-     * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php".
932
-     * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php",
933
-     * then you'd create a file named "templates" in the same folder as it, and name the file
934
-     * "foo_bar_intro.template.php", and its content will be returned by this method
935
-     *
936
-     * @return string
937
-     */
938
-    public function introductory_html(): string
939
-    {
940
-        return EEH_Template::locate_template(
941
-            $this->file_folder() . 'templates/' . strtolower($this->system_name()) . '_intro.template.php',
942
-            ['pmt_obj' => $this, 'pm_instance' => $this->_pm_instance]
943
-        );
944
-    }
19
+	const onsite  = 'on-site';
20
+
21
+	const offsite = 'off-site';
22
+
23
+	const offline = 'off-line';
24
+
25
+	protected ?EE_Payment_Method $_pm_instance = null;
26
+
27
+	protected ?EE_Gateway $_gateway = null;
28
+
29
+	protected ?EE_Payment_Method_Form $_settings_form = null;
30
+
31
+	protected ?EE_Form_Section_Proper $_billing_form = null;
32
+
33
+	protected bool $_cache_billing_form = true;
34
+
35
+	protected ?bool $_has_billing_form;
36
+
37
+	protected bool $_requires_https = false;
38
+
39
+	/**
40
+	 * String of the absolute path to the folder containing this file, with a trailing slash.
41
+	 * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/'
42
+	 *
43
+	 * @var string|null
44
+	 */
45
+	protected $_file_folder = null;
46
+
47
+	/**
48
+	 * String to the absolute URL to this file (useful for getting its web-accessible resources
49
+	 * like images, js, or css)
50
+	 *
51
+	 * @var string|null
52
+	 */
53
+	protected $_file_url = null;
54
+
55
+	/**
56
+	 * Pretty name for the payment method
57
+	 *
58
+	 * @var string|null
59
+	 */
60
+	protected $_pretty_name = null;
61
+
62
+	/**
63
+	 * @var string|null
64
+	 */
65
+	protected $_default_button_url = null;
66
+
67
+	/**
68
+	 * @var string|null
69
+	 */
70
+	protected $_default_description = null;
71
+
72
+	/**
73
+	 * @var string|null
74
+	 */
75
+	protected $_template_path = null;
76
+
77
+
78
+	/**
79
+	 * @param EE_Payment_Method|null $pm_instance
80
+	 * @throws ReflectionException
81
+	 * @throws EE_Error
82
+	 */
83
+	public function __construct($pm_instance = null)
84
+	{
85
+		if ($pm_instance instanceof EE_Payment_Method) {
86
+			$this->set_instance($pm_instance);
87
+		}
88
+		if ($this->_gateway) {
89
+			$this->_gateway->set_payment_model(EEM_Payment::instance());
90
+			$this->_gateway->set_payment_log(EEM_Change_Log::instance());
91
+			$this->_gateway->set_template_helper(new EEH_Template());
92
+			$this->_gateway->set_line_item_helper(new EEH_Line_Item());
93
+			$this->_gateway->set_money_helper(new EEH_Money());
94
+			$this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
95
+			$this->_gateway->set_unsupported_character_remover(new AsciiOnly());
96
+			do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
97
+		}
98
+		if (! isset($this->_has_billing_form)) {
99
+			// by default, On Site gateways have a billing form
100
+			if ($this->payment_occurs() == EE_PMT_Base::onsite) {
101
+				$this->set_has_billing_form(true);
102
+			} else {
103
+				$this->set_has_billing_form(false);
104
+			}
105
+		}
106
+
107
+		if (! $this->_pretty_name) {
108
+			throw new EE_Error(
109
+				esc_html__(
110
+					'You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized',
111
+					'event_espresso'
112
+				)
113
+			);
114
+		}
115
+		// if the child didn't specify a default button, use the credit card one
116
+		if ($this->_default_button_url === null) {
117
+			$this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods/pay-by-credit-card.png';
118
+		}
119
+	}
120
+
121
+
122
+	/**
123
+	 * @param bool|int|string $has_billing_form
124
+	 */
125
+	public function set_has_billing_form($has_billing_form)
126
+	{
127
+		$this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN);
128
+	}
129
+
130
+
131
+	/**
132
+	 * sets the file_folder property
133
+	 */
134
+	protected function _set_file_folder()
135
+	{
136
+		$reflector          = new ReflectionClass(get_class($this));
137
+		$fn                 = $reflector->getFileName();
138
+		$this->_file_folder = dirname($fn) . '/';
139
+	}
140
+
141
+
142
+	/**
143
+	 * sets the file URL with a trailing slash for this PMT
144
+	 */
145
+	protected function _set_file_url()
146
+	{
147
+		$plugins_dir_fixed = str_replace('\\', '/', WP_PLUGIN_DIR);
148
+		$file_folder_fixed = str_replace('\\', '/', $this->file_folder());
149
+		$file_path         = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed);
150
+		$this->_file_url   = set_url_scheme($file_path);
151
+	}
152
+
153
+
154
+	/**
155
+	 * Gets the default description on all payment methods of this type
156
+	 *
157
+	 * @return string
158
+	 */
159
+	public function default_description(): ?string
160
+	{
161
+		return $this->_default_description;
162
+	}
163
+
164
+
165
+	/**
166
+	 * Returns the folder containing the PMT child class, with a trailing slash
167
+	 *
168
+	 * @return string
169
+	 */
170
+	public function file_folder(): ?string
171
+	{
172
+		if (! $this->_file_folder) {
173
+			$this->_set_file_folder();
174
+		}
175
+		return $this->_file_folder;
176
+	}
177
+
178
+
179
+	/**
180
+	 * @return string
181
+	 */
182
+	public function file_url(): ?string
183
+	{
184
+		if (! $this->_file_url) {
185
+			$this->_set_file_url();
186
+		}
187
+		return $this->_file_url;
188
+	}
189
+
190
+
191
+	/**
192
+	 * Sets the payment method instance this payment method type is for.
193
+	 * Its important teh payment method instance is set before
194
+	 *
195
+	 * @param EE_Payment_Method $payment_method_instance
196
+	 * @throws EE_Error
197
+	 * @throws ReflectionException
198
+	 */
199
+	public function set_instance(EE_Payment_Method $payment_method_instance)
200
+	{
201
+		$this->_pm_instance = $payment_method_instance;
202
+		// if they have already requested the settings form, make sure its
203
+		// data matches this model object
204
+		if ($this->_settings_form) {
205
+			$this->settings_form()->populate_model_obj($payment_method_instance);
206
+		}
207
+		if ($this->_gateway instanceof EE_Gateway) {
208
+			$this->_gateway->set_settings($payment_method_instance->settings_array());
209
+		}
210
+	}
211
+
212
+
213
+	/**
214
+	 * Gets teh form for displaying to admins where they set up the payment method
215
+	 *
216
+	 * @return EE_Payment_Method_Form
217
+	 * @throws EE_Error
218
+	 * @throws ReflectionException
219
+	 */
220
+	public function settings_form(): EE_Payment_Method_Form
221
+	{
222
+		if (! $this->_settings_form) {
223
+			$this->_settings_form = $this->generate_new_settings_form();
224
+			$this->_settings_form->set_payment_method_type($this);
225
+			// if we have already assigned a model object to this pmt, make
226
+			// sure it's reflected in the form we just generated
227
+			if ($this->_pm_instance) {
228
+				$this->_settings_form->populate_model_obj($this->_pm_instance);
229
+			}
230
+		}
231
+		return $this->_settings_form;
232
+	}
233
+
234
+
235
+	/**
236
+	 * Gets the form for all the settings related to this payment method type
237
+	 *
238
+	 * @return EE_Payment_Method_Form
239
+	 */
240
+	abstract public function generate_new_settings_form();
241
+
242
+
243
+	/**
244
+	 * Sets the form for settings. This may be useful if we have already received
245
+	 * a form submission and have form data it in, and want to use it anytime we're showing
246
+	 * this payment method type's settings form later in the request
247
+	 *
248
+	 * @param EE_Payment_Method_Form $form
249
+	 */
250
+	public function set_settings_form(EE_Payment_Method_Form $form)
251
+	{
252
+		$this->_settings_form = $form;
253
+	}
254
+
255
+
256
+	/**
257
+	 * @return boolean
258
+	 */
259
+	public function has_billing_form(): bool
260
+	{
261
+		return $this->_has_billing_form;
262
+	}
263
+
264
+
265
+	/**
266
+	 * Gets the form for displaying to attendees where they can enter their billing info
267
+	 * which will be sent to teh gateway (can be null)
268
+	 *
269
+	 * @param EE_Transaction|null $transaction
270
+	 * @param array               $extra_args
271
+	 * @return EE_Billing_Attendee_Info_Form|EE_Billing_Info_Form|null
272
+	 * @throws EE_Error
273
+	 * @throws ReflectionException
274
+	 */
275
+	public function billing_form(EE_Transaction $transaction = null, array $extra_args = [])
276
+	{
277
+		// has billing form already been regenerated ? or overwrite cache?
278
+		if (! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) {
279
+			$this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
280
+		}
281
+		// if we know who the attendee is, and this is a billing form
282
+		// that uses attendee info, populate it
283
+		if (
284
+			apply_filters(
285
+				'FHEE__populate_billing_form_fields_from_attendee',
286
+				(
287
+					$this->_billing_form instanceof EE_Billing_Attendee_Info_Form
288
+					&& $transaction instanceof EE_Transaction
289
+					&& $transaction->primary_registration() instanceof EE_Registration
290
+					&& $transaction->primary_registration()->attendee() instanceof EE_Attendee
291
+				),
292
+				$this->_billing_form,
293
+				$transaction
294
+			)
295
+		) {
296
+			$this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee());
297
+		}
298
+		return $this->_billing_form;
299
+	}
300
+
301
+
302
+	/**
303
+	 * Creates the billing form for this payment method type
304
+	 *
305
+	 * @param EE_Transaction|null $transaction
306
+	 * @return EE_Billing_Info_Form|null
307
+	 */
308
+	abstract public function generate_new_billing_form(EE_Transaction $transaction = null);
309
+
310
+
311
+	/**
312
+	 * applies debug data to the form
313
+	 *
314
+	 * @param EE_Billing_Info_Form $billing_form
315
+	 * @return EE_Billing_Info_Form|null
316
+	 */
317
+	public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form)
318
+	{
319
+		return $billing_form;
320
+	}
321
+
322
+
323
+	/**
324
+	 * Sets the billing form for this payment method type. You may want to use this
325
+	 * if you have form
326
+	 *
327
+	 * @param EE_Billing_Info_Form $form
328
+	 */
329
+	public function set_billing_form(EE_Billing_Info_Form $form)
330
+	{
331
+		$this->_billing_form = $form;
332
+	}
333
+
334
+
335
+	/**
336
+	 * Returns whether this payment method requires HTTPS to be used
337
+	 *
338
+	 * @return boolean
339
+	 */
340
+	public function requires_https(): bool
341
+	{
342
+		return $this->_requires_https;
343
+	}
344
+
345
+
346
+	/**
347
+	 * @param EE_Transaction            $transaction
348
+	 * @param float|null                $amount
349
+	 * @param EE_Billing_Info_Form|null $billing_info
350
+	 * @param string|null               $return_url
351
+	 * @param string                    $fail_url
352
+	 * @param string                    $method
353
+	 * @param bool                      $by_admin
354
+	 * @return EE_Payment
355
+	 * @throws EE_Error
356
+	 * @throws ReflectionException
357
+	 */
358
+	public function process_payment(
359
+		EE_Transaction $transaction,
360
+		$amount = null,
361
+		$billing_info = null,
362
+		$return_url = null,
363
+		$fail_url = '',
364
+		$method = EEM_Payment_Method::scope_cart,
365
+		$by_admin = false
366
+	) {
367
+		$amount = $amount ?: $transaction->remaining();
368
+		$method = EEM_Payment_Method::instance()->is_valid_scope($method) ? $method : EEM_Payment_Method::scope_cart;
369
+
370
+		// if there is billing info, clean it and save it NOW before doing anything else
371
+		if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
372
+			$this->_save_billing_info_to_attendee($billing_info, $transaction);
373
+		}
374
+
375
+		// @todo: add surcharge for the payment method, if any
376
+		if (! $this->_gateway instanceof EE_Gateway) {
377
+			// no gateway provided
378
+			// there is no payment. Must be an offline gateway
379
+			// create a payment object anyways, but don't save it
380
+			return EE_Payment::new_instance(
381
+				[
382
+					'STS_ID'        => EEM_Payment::status_id_pending,
383
+					'TXN_ID'        => $transaction->ID(),
384
+					'PMD_ID'        => $transaction->payment_method_ID(),
385
+					'PAY_amount'    => 0.00,
386
+					'PAY_timestamp' => time(),
387
+				]
388
+			);
389
+		}
390
+
391
+		$payment = $this->getLastPayment($transaction, $amount, $method);
392
+		$payment = $this->validatePayment($transaction, $payment, $amount, $method);
393
+
394
+		$max_payment_attempts   = apply_filters(
395
+			'FHEE__EE_PMT_Base__process_payment__max_payment_attempts',
396
+			5,
397
+			$transaction
398
+		);
399
+		$previous_payment_count = $this->getPreviousPaymentCount($transaction, $amount, $method);
400
+		if ($previous_payment_count >= $max_payment_attempts) {
401
+			return $payment;
402
+		}
403
+
404
+		return $this->passPaymentToGateway($payment, $transaction, $billing_info, $return_url, $fail_url);
405
+	}
406
+
407
+
408
+	/**
409
+	 * Checks for any existing payments that are in a failed state for the same TXN, amount, and method
410
+	 *
411
+	 * @param EE_Transaction $transaction
412
+	 * @param float          $amount
413
+	 * @param string         $method
414
+	 * @return EE_Payment|null
415
+	 * @throws EE_Error
416
+	 * @throws ReflectionException
417
+	 * @since 5.0.28.p
418
+	 */
419
+	private function getLastPayment(EE_Transaction $transaction, float $amount, string $method): ?EE_Payment
420
+	{
421
+		return EEM_Payment::instance()->get_one(
422
+			[
423
+				[
424
+					'STS_ID'     => EEM_Payment::status_id_failed,
425
+					'TXN_ID'     => $transaction->ID(),
426
+					'PMD_ID'     => $this->_pm_instance->ID(),
427
+					'PAY_source' => $method,
428
+					'PAY_amount' => $amount,
429
+				],
430
+			]
431
+		);
432
+	}
433
+
434
+
435
+	/**
436
+	 * IF the last payment was not a failed payment
437
+	 * (which indicates a payment in progress that has yet to be updated),
438
+	 * then create a new payment, otherwise just return the existing payment,
439
+	 * but save it to ensure it has an ID
440
+	 *
441
+	 * @param EE_Transaction  $transaction
442
+	 * @param EE_Payment|null $payment
443
+	 * @param float           $amount
444
+	 * @param string          $method
445
+	 * @return EE_Payment
446
+	 * @throws EE_Error
447
+	 * @throws ReflectionException
448
+	 * @since 5.0.28.p
449
+	 */
450
+	private function validatePayment(
451
+		EE_Transaction $transaction,
452
+		?EE_Payment $payment,
453
+		float $amount,
454
+		string $method
455
+	): EE_Payment {
456
+		if (! $payment instanceof EE_Payment || ! $payment->is_failed()) {
457
+			$payment = EE_Payment::new_instance(
458
+				[
459
+					'PAY_amount'           => $amount,
460
+					'PAY_details'          => null,
461
+					'PAY_extra_accntng'    => null,
462
+					'PAY_gateway_response' => null,
463
+					'PAY_po_number'        => null,
464
+					'PAY_source'           => $method,
465
+					'PAY_timestamp'        => time(),
466
+					'PAY_txn_id_chq_nmbr'  => null,
467
+					'PMD_ID'               => $this->_pm_instance->ID(),
468
+					'STS_ID'               => EEM_Payment::status_id_failed,
469
+					'TXN_ID'               => $transaction->ID(),
470
+				]
471
+			);
472
+		}
473
+		// make sure the payment has been saved to show we started it,
474
+		// and so it has an ID should the gateway try to log it
475
+		$payment->save();
476
+
477
+		return $payment;
478
+	}
479
+
480
+
481
+	/**
482
+	 * Checks for any existing payments that are in a failed state for the same TXN, amount, and method
483
+	 *
484
+	 * @param EE_Transaction $transaction
485
+	 * @param float          $amount
486
+	 * @param string         $method
487
+	 * @return int
488
+	 * @throws EE_Error
489
+	 * @throws ReflectionException
490
+	 * @since 5.0.28.p
491
+	 */
492
+	private function getPreviousPaymentCount(EE_Transaction $transaction, float $amount, string $method): int
493
+	{
494
+		return EEM_Payment::instance()->count(
495
+			[
496
+				[
497
+					'STS_ID'     => [
498
+						'IN',
499
+						[
500
+							EEM_Payment::status_id_pending,
501
+							EEM_Payment::status_id_cancelled,
502
+							EEM_Payment::status_id_declined,
503
+							EEM_Payment::status_id_failed,
504
+						],
505
+					],
506
+					'TXN_ID'     => $transaction->ID(),
507
+					'PMD_ID'     => $this->_pm_instance->ID(),
508
+					'PAY_source' => $method,
509
+					'PAY_amount' => $amount,
510
+				],
511
+				'order_by' => ['PAY_timestamp' => 'DESC'],
512
+			]
513
+		);
514
+	}
515
+
516
+
517
+	/**
518
+	 * @param EE_Payment                $payment
519
+	 * @param EE_Transaction            $transaction
520
+	 * @param EE_Billing_Info_Form|null $billing_info
521
+	 * @param string|null               $return_url
522
+	 * @param string|null               $fail_url
523
+	 * @return EE_Payment
524
+	 * @throws EE_Error
525
+	 * @throws ReflectionException
526
+	 * @since 5.0.28.p
527
+	 */
528
+	private function passPaymentToGateway(
529
+		EE_Payment $payment,
530
+		EE_Transaction $transaction,
531
+		?EE_Billing_Info_Form $billing_info,
532
+		?string $return_url = null,
533
+		?string $fail_url = ''
534
+	): EE_Payment {
535
+		$billing_values = $this->_get_billing_values_from_form($billing_info);
536
+		if ($this->_gateway instanceof EE_Offsite_Gateway) {
537
+			$payment = $this->_gateway->set_redirection_info(
538
+				$payment,
539
+				$billing_values,
540
+				$return_url,
541
+				EE_Config::instance()->core->txn_page_url(
542
+					[
543
+						'e_reg_url_link'    => $transaction->primary_registration()->reg_url_link(),
544
+						'ee_payment_method' => $this->_pm_instance->slug(),
545
+					]
546
+				),
547
+				$fail_url
548
+			);
549
+			$payment->save();
550
+		} elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
551
+			$payment = $this->_gateway->do_direct_payment($payment, $billing_values);
552
+			$payment->save();
553
+		} else {
554
+			throw new EE_Error(
555
+				sprintf(
556
+					esc_html__(
557
+						'Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)',
558
+						'event_espresso'
559
+					),
560
+					get_class($this),
561
+					gettype($this->_gateway)
562
+				)
563
+			);
564
+		}
565
+		return $payment;
566
+	}
567
+
568
+
569
+	/**
570
+	 * Gets the values we want to pass onto the gateway. Normally these
571
+	 * are just the 'pretty' values, but there may be times the data may need
572
+	 * a  little massaging. Proper subsections will become arrays of inputs
573
+	 *
574
+	 * @param EE_Billing_Info_Form|null $billing_form
575
+	 * @return array
576
+	 * @throws EE_Error
577
+	 */
578
+	protected function _get_billing_values_from_form($billing_form)
579
+	{
580
+		return $billing_form instanceof EE_Form_Section_Proper
581
+			? $billing_form->input_pretty_values(true)
582
+			: [];
583
+	}
584
+
585
+
586
+	/**
587
+	 * Handles an instant payment notification when the transaction is known (by default).
588
+	 *
589
+	 * @param array          $req_data
590
+	 * @param EE_Transaction $transaction
591
+	 * @return EE_Payment
592
+	 * @throws EE_Error
593
+	 * @throws ReflectionException
594
+	 */
595
+	public function handle_ipn(array $req_data, EE_Transaction $transaction): EE_Payment
596
+	{
597
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
598
+		if (! $this->_gateway instanceof EE_Offsite_Gateway) {
599
+			throw new EE_Error(
600
+				sprintf(
601
+					esc_html__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"),
602
+					print_r($this->_gateway, true)
603
+				)
604
+			);
605
+		}
606
+		return $this->_gateway->handle_payment_update($req_data, $transaction);
607
+	}
608
+
609
+
610
+	/**
611
+	 * Saves the billing info onto the attendee of the primary registrant on this transaction, and
612
+	 * cleans it first.
613
+	 *
614
+	 * @param EE_Billing_Attendee_Info_Form $billing_form
615
+	 * @param EE_Transaction|null           $transaction
616
+	 * @return boolean success
617
+	 * @throws EE_Error
618
+	 * @throws ReflectionException
619
+	 */
620
+	protected function _save_billing_info_to_attendee(
621
+		EE_Billing_Attendee_Info_Form $billing_form,
622
+		?EE_Transaction $transaction
623
+	): bool {
624
+		if (! $transaction instanceof EE_Transaction) {
625
+			EE_Error::add_error(
626
+				esc_html__("Cannot save billing info because no transaction was specified", "event_espresso"),
627
+				__FILE__,
628
+				__FUNCTION__,
629
+				__LINE__
630
+			);
631
+			return false;
632
+		}
633
+		$primary_reg = $transaction->primary_registration();
634
+		if (! $primary_reg) {
635
+			EE_Error::add_error(
636
+				esc_html__(
637
+					"Cannot save billing info because the transaction has no primary registration",
638
+					"event_espresso"
639
+				),
640
+				__FILE__,
641
+				__FUNCTION__,
642
+				__LINE__
643
+			);
644
+			return false;
645
+		}
646
+		$attendee = $primary_reg->attendee();
647
+		if (! $attendee) {
648
+			EE_Error::add_error(
649
+				esc_html__(
650
+					"Cannot save billing info because the transaction's primary registration has no attendee!",
651
+					"event_espresso"
652
+				),
653
+				__FILE__,
654
+				__FUNCTION__,
655
+				__LINE__
656
+			);
657
+			return false;
658
+		}
659
+		return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
660
+	}
661
+
662
+
663
+	/**
664
+	 * Gets the payment this IPN is for. Children may often want to
665
+	 * override this to inspect the request
666
+	 *
667
+	 * @param EE_Transaction $transaction
668
+	 * @param array          $req_data
669
+	 * @return EE_Payment
670
+	 * @throws EE_Error
671
+	 * @throws ReflectionException
672
+	 */
673
+	protected function find_payment_for_ipn(EE_Transaction $transaction, array $req_data = []): EE_Payment
674
+	{
675
+		return $transaction->last_payment();
676
+	}
677
+
678
+
679
+	/**
680
+	 * In case generic code cannot provide the payment processor with a specific payment method
681
+	 * and transaction, it will try calling this method on each activate payment method.
682
+	 * If the payment method is able to identify the request as being for it, it should fetch
683
+	 * the payment it's for and return it. If not, it should throw an EE_Error to indicate it cannot
684
+	 * handle the IPN
685
+	 *
686
+	 * @param array $req_data
687
+	 * @return EE_Payment only if this payment method can find the info its needs from $req_data
688
+	 * and identifies the IPN as being for this payment method (not just fo ra payment method of this type)
689
+	 * @throws EE_Error
690
+	 */
691
+	public function handle_unclaimed_ipn(array $req_data = []): EE_Payment
692
+	{
693
+		throw new EE_Error(
694
+			sprintf(
695
+				esc_html__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"),
696
+				get_class($this)
697
+			)
698
+		);
699
+	}
700
+
701
+
702
+	/**
703
+	 * Logic to be accomplished when the payment attempt is complete.
704
+	 * Most payment methods don't need to do anything at this point; but some, like Mijireh, do.
705
+	 * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from
706
+	 * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status
707
+	 * of the payment). Fed a transaction because it's always assumed to be the last payment that
708
+	 * we're dealing with. Returns that last payment (if there is one)
709
+	 *
710
+	 * @param EE_Transaction $transaction
711
+	 * @return EE_Payment|null
712
+	 * @throws EE_Error
713
+	 * @throws ReflectionException
714
+	 */
715
+	public function finalize_payment_for(EE_Transaction $transaction): ?EE_Payment
716
+	{
717
+		return $transaction->last_payment();
718
+	}
719
+
720
+
721
+	/**
722
+	 * Whether this payment method's gateway supports sending refund requests
723
+	 *
724
+	 * @return boolean
725
+	 */
726
+	public function supports_sending_refunds(): bool
727
+	{
728
+		return $this->_gateway instanceof EE_Gateway && $this->_gateway->supports_sending_refunds();
729
+	}
730
+
731
+
732
+	/**
733
+	 * @param EE_Payment $payment
734
+	 * @param array      $refund_info
735
+	 * @return EE_Payment
736
+	 * @throws EE_Error
737
+	 */
738
+	public function process_refund(EE_Payment $payment, array $refund_info = []): EE_Payment
739
+	{
740
+		if ($this->_gateway instanceof EE_Gateway) {
741
+			return $this->_gateway->do_direct_refund($payment, $refund_info);
742
+		} else {
743
+			throw new EE_Error(
744
+				sprintf(
745
+					esc_html__('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'),
746
+					get_class($this)
747
+				)
748
+			);
749
+		}
750
+	}
751
+
752
+
753
+	/**
754
+	 * Returns one the class's constants onsite,offsite, or offline, depending on this
755
+	 * payment method's gateway.
756
+	 *
757
+	 * @return string
758
+	 * @throws EE_Error
759
+	 */
760
+	public function payment_occurs(): string
761
+	{
762
+		if (! $this->_gateway) {
763
+			return EE_PMT_Base::offline;
764
+		}
765
+		if ($this->_gateway instanceof EE_Onsite_Gateway) {
766
+			return EE_PMT_Base::onsite;
767
+		}
768
+		if ($this->_gateway instanceof EE_Offsite_Gateway) {
769
+			return EE_PMT_Base::offsite;
770
+		}
771
+		throw new EE_Error(
772
+			sprintf(
773
+				esc_html__(
774
+					"Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those",
775
+					"event_espresso"
776
+				),
777
+				get_class($this)
778
+			)
779
+		);
780
+	}
781
+
782
+
783
+	/**
784
+	 * For adding any html output ab ove the payment overview.
785
+	 * Many gateways won't want ot display anything, so this function just returns an empty string.
786
+	 * Other gateways may want to override this, such as offline gateways.
787
+	 *
788
+	 * @param EE_Payment $payment
789
+	 * @return string
790
+	 */
791
+	public function payment_overview_content(EE_Payment $payment)
792
+	{
793
+		return EEH_Template::display_template(
794
+			EE_LIBRARIES . 'payment_methods/templates/payment_details_content.template.php',
795
+			['payment_method' => $this->_pm_instance, 'payment' => $payment],
796
+			true
797
+		);
798
+	}
799
+
800
+
801
+	/**
802
+	 * @return array where keys are the help tab name,
803
+	 * values are: array {
804
+	 * @type string $title         i18n name for the help tab
805
+	 * @type string $filename      name of the file located in ./help_tabs/ (ie, in a folder next to this file)
806
+	 * @type array  $template_args any arguments you want passed to the template file while rendering.
807
+	 *                             Keys will be variable names and values with be their values.
808
+	 */
809
+	public function help_tabs_config()
810
+	{
811
+		return [];
812
+	}
813
+
814
+
815
+	/**
816
+	 * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into
817
+	 * the payment method's table's PMT_type column)
818
+	 *
819
+	 * @return string
820
+	 */
821
+	public function system_name()
822
+	{
823
+		$classname = get_class($this);
824
+		return str_replace("EE_PMT_", '', $classname);
825
+	}
826
+
827
+
828
+	/**
829
+	 * A pretty i18n version of the PMT name. Often the same as the "pretty_name", but you can change it by overriding
830
+	 * this method.
831
+	 *
832
+	 * @return string|null
833
+	 */
834
+	public function defaultFrontendName()
835
+	{
836
+		return $this->pretty_name();
837
+	}
838
+
839
+
840
+	/**
841
+	 * A pretty i18n version of the PMT name
842
+	 *
843
+	 * @return string|null
844
+	 */
845
+	public function pretty_name(): ?string
846
+	{
847
+		return $this->_pretty_name;
848
+	}
849
+
850
+
851
+	/**
852
+	 * Gets the default absolute URL to the payment method type's button
853
+	 *
854
+	 * @return string|null
855
+	 */
856
+	public function default_button_url(): ?string
857
+	{
858
+		return $this->_default_button_url;
859
+	}
860
+
861
+
862
+	/**
863
+	 * Gets the gateway used by this payment method (if any)
864
+	 *
865
+	 * @return EE_Gateway
866
+	 */
867
+	public function get_gateway(): ?EE_Gateway
868
+	{
869
+		return $this->_gateway;
870
+	}
871
+
872
+
873
+	/**
874
+	 * @return string html for the link to a help tab
875
+	 */
876
+	public function get_help_tab_link(): string
877
+	{
878
+		return EEH_Template::get_help_tab_link(
879
+			$this->get_help_tab_name(),
880
+			'espresso_payment_settings',
881
+			'default'
882
+		);
883
+	}
884
+
885
+
886
+	/**
887
+	 * Returns the name of the help tab for this PMT
888
+	 *
889
+	 * @return string
890
+	 */
891
+	public function get_help_tab_name(): string
892
+	{
893
+		return 'ee_' . strtolower($this->system_name()) . '_help_tab';
894
+	}
895
+
896
+
897
+	/**
898
+	 * The name of the wp capability that should be associated with the usage of
899
+	 * this PMT by an admin
900
+	 *
901
+	 * @return string
902
+	 */
903
+	public function cap_name(): string
904
+	{
905
+		return 'ee_payment_method_' . strtolower($this->system_name());
906
+	}
907
+
908
+
909
+	/**
910
+	 * Called by client code to tell the gateway that if it wants to change
911
+	 * the transaction or line items or registrations related to teh payment it already
912
+	 * processed (we think, but possibly not) that now's the time to do it.
913
+	 * It is expected that gateways will store any info they need for this on the PAY_details,
914
+	 * or maybe an extra meta value
915
+	 *
916
+	 * @param EE_Payment $payment
917
+	 * @return void
918
+	 */
919
+	public function update_txn_based_on_payment($payment)
920
+	{
921
+		if ($this->_gateway instanceof EE_Gateway) {
922
+			$this->_gateway->update_txn_based_on_payment($payment);
923
+		}
924
+	}
925
+
926
+
927
+	/**
928
+	 * Returns a string of HTML describing this payment method type for an admin,
929
+	 * primarily intended for them to read before activating it.
930
+	 * The easiest way to set this is to create a folder 'templates' alongside
931
+	 * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php".
932
+	 * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php",
933
+	 * then you'd create a file named "templates" in the same folder as it, and name the file
934
+	 * "foo_bar_intro.template.php", and its content will be returned by this method
935
+	 *
936
+	 * @return string
937
+	 */
938
+	public function introductory_html(): string
939
+	{
940
+		return EEH_Template::locate_template(
941
+			$this->file_folder() . 'templates/' . strtolower($this->system_name()) . '_intro.template.php',
942
+			['pmt_obj' => $this, 'pm_instance' => $this->_pm_instance]
943
+		);
944
+	}
945 945
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
             $this->_gateway->set_unsupported_character_remover(new AsciiOnly());
96 96
             do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
97 97
         }
98
-        if (! isset($this->_has_billing_form)) {
98
+        if ( ! isset($this->_has_billing_form)) {
99 99
             // by default, On Site gateways have a billing form
100 100
             if ($this->payment_occurs() == EE_PMT_Base::onsite) {
101 101
                 $this->set_has_billing_form(true);
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
             }
105 105
         }
106 106
 
107
-        if (! $this->_pretty_name) {
107
+        if ( ! $this->_pretty_name) {
108 108
             throw new EE_Error(
109 109
                 esc_html__(
110 110
                     'You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized',
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         }
115 115
         // if the child didn't specify a default button, use the credit card one
116 116
         if ($this->_default_button_url === null) {
117
-            $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods/pay-by-credit-card.png';
117
+            $this->_default_button_url = EE_PLUGIN_DIR_URL.'payment_methods/pay-by-credit-card.png';
118 118
         }
119 119
     }
120 120
 
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     {
136 136
         $reflector          = new ReflectionClass(get_class($this));
137 137
         $fn                 = $reflector->getFileName();
138
-        $this->_file_folder = dirname($fn) . '/';
138
+        $this->_file_folder = dirname($fn).'/';
139 139
     }
140 140
 
141 141
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
      */
170 170
     public function file_folder(): ?string
171 171
     {
172
-        if (! $this->_file_folder) {
172
+        if ( ! $this->_file_folder) {
173 173
             $this->_set_file_folder();
174 174
         }
175 175
         return $this->_file_folder;
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
      */
182 182
     public function file_url(): ?string
183 183
     {
184
-        if (! $this->_file_url) {
184
+        if ( ! $this->_file_url) {
185 185
             $this->_set_file_url();
186 186
         }
187 187
         return $this->_file_url;
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      */
220 220
     public function settings_form(): EE_Payment_Method_Form
221 221
     {
222
-        if (! $this->_settings_form) {
222
+        if ( ! $this->_settings_form) {
223 223
             $this->_settings_form = $this->generate_new_settings_form();
224 224
             $this->_settings_form->set_payment_method_type($this);
225 225
             // if we have already assigned a model object to this pmt, make
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
     public function billing_form(EE_Transaction $transaction = null, array $extra_args = [])
276 276
     {
277 277
         // has billing form already been regenerated ? or overwrite cache?
278
-        if (! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) {
278
+        if ( ! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) {
279 279
             $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
280 280
         }
281 281
         // if we know who the attendee is, and this is a billing form
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
         }
374 374
 
375 375
         // @todo: add surcharge for the payment method, if any
376
-        if (! $this->_gateway instanceof EE_Gateway) {
376
+        if ( ! $this->_gateway instanceof EE_Gateway) {
377 377
             // no gateway provided
378 378
             // there is no payment. Must be an offline gateway
379 379
             // create a payment object anyways, but don't save it
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
         $payment = $this->getLastPayment($transaction, $amount, $method);
392 392
         $payment = $this->validatePayment($transaction, $payment, $amount, $method);
393 393
 
394
-        $max_payment_attempts   = apply_filters(
394
+        $max_payment_attempts = apply_filters(
395 395
             'FHEE__EE_PMT_Base__process_payment__max_payment_attempts',
396 396
             5,
397 397
             $transaction
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
         float $amount,
454 454
         string $method
455 455
     ): EE_Payment {
456
-        if (! $payment instanceof EE_Payment || ! $payment->is_failed()) {
456
+        if ( ! $payment instanceof EE_Payment || ! $payment->is_failed()) {
457 457
             $payment = EE_Payment::new_instance(
458 458
                 [
459 459
                     'PAY_amount'           => $amount,
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
     public function handle_ipn(array $req_data, EE_Transaction $transaction): EE_Payment
596 596
     {
597 597
         $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
598
-        if (! $this->_gateway instanceof EE_Offsite_Gateway) {
598
+        if ( ! $this->_gateway instanceof EE_Offsite_Gateway) {
599 599
             throw new EE_Error(
600 600
                 sprintf(
601 601
                     esc_html__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"),
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
         EE_Billing_Attendee_Info_Form $billing_form,
622 622
         ?EE_Transaction $transaction
623 623
     ): bool {
624
-        if (! $transaction instanceof EE_Transaction) {
624
+        if ( ! $transaction instanceof EE_Transaction) {
625 625
             EE_Error::add_error(
626 626
                 esc_html__("Cannot save billing info because no transaction was specified", "event_espresso"),
627 627
                 __FILE__,
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
             return false;
632 632
         }
633 633
         $primary_reg = $transaction->primary_registration();
634
-        if (! $primary_reg) {
634
+        if ( ! $primary_reg) {
635 635
             EE_Error::add_error(
636 636
                 esc_html__(
637 637
                     "Cannot save billing info because the transaction has no primary registration",
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
             return false;
645 645
         }
646 646
         $attendee = $primary_reg->attendee();
647
-        if (! $attendee) {
647
+        if ( ! $attendee) {
648 648
             EE_Error::add_error(
649 649
                 esc_html__(
650 650
                     "Cannot save billing info because the transaction's primary registration has no attendee!",
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
      */
760 760
     public function payment_occurs(): string
761 761
     {
762
-        if (! $this->_gateway) {
762
+        if ( ! $this->_gateway) {
763 763
             return EE_PMT_Base::offline;
764 764
         }
765 765
         if ($this->_gateway instanceof EE_Onsite_Gateway) {
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
     public function payment_overview_content(EE_Payment $payment)
792 792
     {
793 793
         return EEH_Template::display_template(
794
-            EE_LIBRARIES . 'payment_methods/templates/payment_details_content.template.php',
794
+            EE_LIBRARIES.'payment_methods/templates/payment_details_content.template.php',
795 795
             ['payment_method' => $this->_pm_instance, 'payment' => $payment],
796 796
             true
797 797
         );
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
      */
891 891
     public function get_help_tab_name(): string
892 892
     {
893
-        return 'ee_' . strtolower($this->system_name()) . '_help_tab';
893
+        return 'ee_'.strtolower($this->system_name()).'_help_tab';
894 894
     }
895 895
 
896 896
 
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
      */
903 903
     public function cap_name(): string
904 904
     {
905
-        return 'ee_payment_method_' . strtolower($this->system_name());
905
+        return 'ee_payment_method_'.strtolower($this->system_name());
906 906
     }
907 907
 
908 908
 
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
     public function introductory_html(): string
939 939
     {
940 940
         return EEH_Template::locate_template(
941
-            $this->file_folder() . 'templates/' . strtolower($this->system_name()) . '_intro.template.php',
941
+            $this->file_folder().'templates/'.strtolower($this->system_name()).'_intro.template.php',
942 942
             ['pmt_obj' => $this, 'pm_instance' => $this->_pm_instance]
943 943
         );
944 944
     }
Please login to merge, or discard this patch.
core/services/orm/ModelFieldFactory.php 1 patch
Indentation   +619 added lines, -619 removed lines patch added patch discarded remove patch
@@ -46,623 +46,623 @@
 block discarded – undo
46 46
  */
47 47
 class ModelFieldFactory
48 48
 {
49
-    /**
50
-     * @var LoaderInterface $loader
51
-     */
52
-    private $loader;
53
-
54
-
55
-    /**
56
-     * ModelFieldFactory constructor.
57
-     *
58
-     * @param LoaderInterface $loader
59
-     */
60
-    public function __construct(LoaderInterface $loader)
61
-    {
62
-        $this->loader = $loader;
63
-    }
64
-
65
-
66
-    /**
67
-     * @param string $table_column
68
-     * @param string $nice_name
69
-     * @param bool   $nullable
70
-     * @param null   $default_value
71
-     * @return EE_All_Caps_Text_Field
72
-     */
73
-    public function createAllCapsTextField(
74
-        string $table_column,
75
-        string $nice_name,
76
-        bool $nullable,
77
-        $default_value = null
78
-    ): EE_All_Caps_Text_Field {
79
-        return $this->loader->getNew(
80
-            'EE_All_Caps_Text_Field',
81
-            [$table_column, $nice_name, $nullable, $default_value]
82
-        );
83
-    }
84
-
85
-
86
-    /**
87
-     * @param string $table_column
88
-     * @param string $nice_name
89
-     * @param bool   $nullable
90
-     * @param null   $default_value
91
-     * @param string $model_name
92
-     * @return EE_Any_Foreign_Model_Name_Field
93
-     */
94
-    public function createAnyForeignModelNameField(
95
-        string $table_column,
96
-        string $nice_name,
97
-        bool $nullable,
98
-        $default_value = null,
99
-        string $model_name = ''
100
-    ): EE_Any_Foreign_Model_Name_Field {
101
-        return $this->loader->getNew(
102
-            'EE_Any_Foreign_Model_Name_Field',
103
-            [$table_column, $nice_name, $nullable, $default_value, $model_name]
104
-        );
105
-    }
106
-
107
-
108
-    /**
109
-     * @param string $table_column
110
-     * @param string $nice_name
111
-     * @param bool   $nullable
112
-     * @param null   $default_value
113
-     * @return EE_Boolean_Field
114
-     */
115
-    public function createBooleanField(
116
-        string $table_column,
117
-        string $nice_name,
118
-        bool $nullable,
119
-        $default_value = null
120
-    ): EE_Boolean_Field {
121
-        return $this->loader->getNew(
122
-            'EE_Boolean_Field',
123
-            [$table_column, $nice_name, $nullable, $default_value]
124
-        );
125
-    }
126
-
127
-
128
-    /**
129
-     * @param string $table_column
130
-     * @param string $nice_name
131
-     * @param bool   $nullable
132
-     * @param string $default_value
133
-     * @param string $timezone_string
134
-     * @return EE_Datetime_Field
135
-     */
136
-    public function createDatetimeField(
137
-        string $table_column,
138
-        string $nice_name,
139
-        bool $nullable = false,
140
-        string $default_value = EE_Datetime_Field::now,
141
-        string $timezone_string = ''
142
-    ): EE_Datetime_Field {
143
-        return $this->loader->getNew(
144
-            'EE_Datetime_Field',
145
-            [$table_column, $nice_name, $nullable, $default_value, $timezone_string]
146
-        );
147
-    }
148
-
149
-
150
-    /**
151
-     * @param string $table_column
152
-     * @param string $nice_name
153
-     * @param bool   $nullable
154
-     * @param null   $default_value
155
-     * @return EE_DB_Only_Float_Field
156
-     */
157
-    public function createDbOnlyFloatField(
158
-        string $table_column,
159
-        string $nice_name,
160
-        bool $nullable,
161
-        $default_value = null
162
-    ): EE_DB_Only_Float_Field {
163
-        return $this->loader->getNew(
164
-            'EE_DB_Only_Float_Field',
165
-            [$table_column, $nice_name, $nullable, $default_value]
166
-        );
167
-    }
168
-
169
-
170
-    /**
171
-     * @param string $table_column
172
-     * @param string $nice_name
173
-     * @param bool   $nullable
174
-     * @param null   $default_value
175
-     * @return EE_DB_Only_Int_Field
176
-     */
177
-    public function createDbOnlyIntField(
178
-        string $table_column,
179
-        string $nice_name,
180
-        bool $nullable,
181
-        $default_value = null
182
-    ): EE_DB_Only_Int_Field {
183
-        return $this->loader->getNew(
184
-            'EE_DB_Only_Int_Field',
185
-            [$table_column, $nice_name, $nullable, $default_value]
186
-        );
187
-    }
188
-
189
-
190
-    /**
191
-     * @param string $table_column
192
-     * @param string $nice_name
193
-     * @param bool   $nullable
194
-     * @param null   $default_value
195
-     * @return EE_DB_Only_Text_Field
196
-     */
197
-    public function createDbOnlyTextField(
198
-        string $table_column,
199
-        string $nice_name,
200
-        bool $nullable,
201
-        $default_value = null
202
-    ): EE_DB_Only_Text_Field {
203
-        return $this->loader->getNew(
204
-            'EE_DB_Only_Text_Field',
205
-            [$table_column, $nice_name, $nullable, $default_value]
206
-        );
207
-    }
208
-
209
-
210
-    /**
211
-     * @param string      $table_column
212
-     * @param string      $nice_name
213
-     * @param bool        $nullable
214
-     * @param string|null $default_value
215
-     * @return EE_Email_Field
216
-     */
217
-    public function createEmailField(
218
-        string $table_column,
219
-        string $nice_name,
220
-        bool $nullable = true,
221
-        string $default_value = ''
222
-    ): EE_Email_Field {
223
-        return $this->loader->getNew(
224
-            'EE_Email_Field',
225
-            [$table_column, $nice_name, $nullable, $default_value]
226
-        );
227
-    }
228
-
229
-
230
-    /**
231
-     * @param string $table_column
232
-     * @param string $nice_name
233
-     * @param bool   $nullable
234
-     * @param null   $default_value
235
-     * @param array  $allowed_enum_values keys are values to be used in the DB,
236
-     *                                    values are how they should be displayed
237
-     * @return EE_Enum_Integer_Field
238
-     */
239
-    public function createEnumIntegerField(
240
-        string $table_column,
241
-        string $nice_name,
242
-        bool $nullable,
243
-        $default_value = null,
244
-        array $allowed_enum_values = []
245
-    ): EE_Enum_Integer_Field {
246
-        return $this->loader->getNew(
247
-            'EE_Enum_Integer_Field',
248
-            [$table_column, $nice_name, $nullable, $default_value, $allowed_enum_values]
249
-        );
250
-    }
251
-
252
-
253
-    /**
254
-     * @param string $table_column
255
-     * @param string $nice_name
256
-     * @param bool   $nullable
257
-     * @param null   $default_value
258
-     * @param array  $allowed_enum_values keys are values to be used in the DB,
259
-     *                                    values are how they should be displayed
260
-     * @return EE_Enum_Text_Field
261
-     */
262
-    public function createEnumTextField(
263
-        string $table_column,
264
-        string $nice_name,
265
-        bool $nullable,
266
-        $default_value,
267
-        array $allowed_enum_values
268
-    ): EE_Enum_Text_Field {
269
-        return $this->loader->getNew(
270
-            'EE_Enum_Text_Field',
271
-            [$table_column, $nice_name, $nullable, $default_value, $allowed_enum_values]
272
-        );
273
-    }
274
-
275
-
276
-    /**
277
-     * @param string $table_column
278
-     * @param string $nice_name
279
-     * @param bool   $nullable
280
-     * @param null   $default_value
281
-     * @return EE_Float_Field
282
-     */
283
-    public function createFloatField(
284
-        string $table_column,
285
-        string $nice_name,
286
-        bool $nullable,
287
-        $default_value = null
288
-    ): EE_Float_Field {
289
-        return $this->loader->getNew(
290
-            'EE_Float_Field',
291
-            [$table_column, $nice_name, $nullable, $default_value]
292
-        );
293
-    }
294
-
295
-
296
-    /**
297
-     * @param string $table_column
298
-     * @param string $nice_name
299
-     * @param bool   $nullable
300
-     * @param null   $default_value
301
-     * @param string $model_name
302
-     * @return EE_Foreign_Key_Int_Field
303
-     */
304
-    public function createForeignKeyIntField(
305
-        string $table_column,
306
-        string $nice_name,
307
-        bool $nullable,
308
-        $default_value,
309
-        string $model_name
310
-    ): EE_Foreign_Key_Int_Field {
311
-        return $this->loader->getNew(
312
-            'EE_Foreign_Key_Int_Field',
313
-            [$table_column, $nice_name, $nullable, $default_value, $model_name]
314
-        );
315
-    }
316
-
317
-
318
-    /**
319
-     * @param string $table_column
320
-     * @param string $nice_name
321
-     * @param bool   $nullable
322
-     * @param null   $default_value
323
-     * @param string $model_name
324
-     * @return EE_Foreign_Key_String_Field
325
-     */
326
-    public function createForeignKeyStringField(
327
-        string $table_column,
328
-        string $nice_name,
329
-        bool $nullable,
330
-        $default_value,
331
-        string $model_name
332
-    ): EE_Foreign_Key_String_Field {
333
-        return $this->loader->getNew(
334
-            'EE_Foreign_Key_String_Field',
335
-            [$table_column, $nice_name, $nullable, $default_value, $model_name]
336
-        );
337
-    }
338
-
339
-
340
-    /**
341
-     * @param string $table_column
342
-     * @param string $nice_name
343
-     * @param bool   $nullable
344
-     * @param null   $default_value
345
-     * @return EE_Full_HTML_Field
346
-     */
347
-    public function createFullHtmlField(
348
-        string $table_column,
349
-        string $nice_name,
350
-        bool $nullable,
351
-        $default_value = null
352
-    ): EE_Full_HTML_Field {
353
-        return $this->loader->getNew(
354
-            'EE_Full_HTML_Field',
355
-            [$table_column, $nice_name, $nullable, $default_value]
356
-        );
357
-    }
358
-
359
-
360
-    /**
361
-     * @param string $table_column
362
-     * @param string $nice_name
363
-     * @param bool   $nullable
364
-     * @param null   $default_value
365
-     * @return EE_Infinite_Integer_Field
366
-     */
367
-    public function createInfiniteIntegerField(
368
-        string $table_column,
369
-        string $nice_name,
370
-        bool $nullable,
371
-        $default_value = null
372
-    ): EE_Infinite_Integer_Field {
373
-        return $this->loader->getNew(
374
-            'EE_Infinite_Integer_Field',
375
-            [$table_column, $nice_name, $nullable, $default_value]
376
-        );
377
-    }
378
-
379
-
380
-    /**
381
-     * @param string  $table_column
382
-     * @param string  $nice_name
383
-     * @param bool    $nullable
384
-     * @param integer $default_value
385
-     * @return EE_Integer_Field
386
-     */
387
-    public function createIntegerField(
388
-        string $table_column,
389
-        string $nice_name,
390
-        bool $nullable = false,
391
-        int $default_value = 0
392
-    ): EE_Integer_Field {
393
-        return $this->loader->getNew(
394
-            'EE_Integer_Field',
395
-            [$table_column, $nice_name, $nullable, $default_value]
396
-        );
397
-    }
398
-
399
-
400
-    /**
401
-     * @param string $table_column
402
-     * @param string $nice_name
403
-     * @param bool   $nullable
404
-     * @param null   $default_value
405
-     * @return EE_Maybe_Serialized_Simple_HTML_Field
406
-     */
407
-    public function createMaybeSerializedSimpleHtmlField(
408
-        string $table_column,
409
-        string $nice_name,
410
-        bool $nullable,
411
-        $default_value = null
412
-    ): EE_Maybe_Serialized_Simple_HTML_Field {
413
-        return $this->loader->getNew(
414
-            'EE_Maybe_Serialized_Simple_HTML_Field',
415
-            [$table_column, $nice_name, $nullable, $default_value]
416
-        );
417
-    }
418
-
419
-
420
-    /**
421
-     * @param string $table_column
422
-     * @param string $nice_name
423
-     * @param bool   $nullable
424
-     * @param null   $default_value
425
-     * @return EE_Maybe_Serialized_Text_Field
426
-     */
427
-    public function createMaybeSerializedTextField(
428
-        string $table_column,
429
-        string $nice_name,
430
-        bool $nullable,
431
-        $default_value = null
432
-    ): EE_Maybe_Serialized_Text_Field {
433
-        return $this->loader->getNew(
434
-            'EE_Maybe_Serialized_Text_Field',
435
-            [$table_column, $nice_name, $nullable, $default_value]
436
-        );
437
-    }
438
-
439
-
440
-    /**
441
-     * @param string $table_column
442
-     * @param string $nice_name
443
-     * @param bool   $nullable
444
-     * @param null   $default_value
445
-     * @return EE_Money_Field
446
-     */
447
-    public function createMoneyField(
448
-        string $table_column,
449
-        string $nice_name,
450
-        bool $nullable,
451
-        $default_value = null
452
-    ): EE_Money_Field {
453
-        return $this->loader->getNew(
454
-            'EE_Money_Field',
455
-            [$table_column, $nice_name, $nullable, $default_value]
456
-        );
457
-    }
458
-
459
-
460
-    /**
461
-     * @param string $table_column
462
-     * @param string $nice_name
463
-     * @param bool   $nullable
464
-     * @param string $default_value
465
-     * @return EE_Plain_Text_Field
466
-     */
467
-    public function createPlainTextField(
468
-        string $table_column,
469
-        string $nice_name,
470
-        bool $nullable = true,
471
-        string $default_value = ''
472
-    ): EE_Plain_Text_Field {
473
-        return $this->loader->getNew(
474
-            'EE_Plain_Text_Field',
475
-            [$table_column, $nice_name, $nullable, $default_value]
476
-        );
477
-    }
478
-
479
-
480
-    /**
481
-     * @param string $table_column
482
-     * @param string $nice_name
483
-     * @param bool   $nullable
484
-     * @param null   $default_value
485
-     * @return EE_Post_Content_Field
486
-     */
487
-    public function createPostContentField(
488
-        string $table_column,
489
-        string $nice_name,
490
-        bool $nullable,
491
-        $default_value = null
492
-    ): EE_Post_Content_Field {
493
-        return $this->loader->getNew(
494
-            'EE_Post_Content_Field',
495
-            [$table_column, $nice_name, $nullable, $default_value]
496
-        );
497
-    }
498
-
499
-
500
-    /**
501
-     * @param string $table_column
502
-     * @param string $nice_name
503
-     * @return EE_Primary_Key_Int_Field
504
-     */
505
-    public function createPrimaryKeyIntField(string $table_column, string $nice_name): EE_Primary_Key_Int_Field
506
-    {
507
-        return $this->loader->getNew('EE_Primary_Key_Int_Field', [$table_column, $nice_name]);
508
-    }
509
-
510
-
511
-    /**
512
-     * @param string $table_column
513
-     * @param string $nice_name
514
-     * @return EE_Primary_Key_String_Field
515
-     */
516
-    public function createPrimaryKeyStringField(string $table_column, string $nice_name): EE_Primary_Key_String_Field
517
-    {
518
-        return $this->loader->getNew('EE_Primary_Key_String_Field', [$table_column, $nice_name]);
519
-    }
520
-
521
-
522
-    /**
523
-     * @param string $table_column
524
-     * @param string $nice_name
525
-     * @param bool   $nullable
526
-     * @param null   $default_value
527
-     * @return EE_Serialized_Text_Field
528
-     */
529
-    public function createSerializedTextField(
530
-        string $table_column,
531
-        string $nice_name,
532
-        bool $nullable,
533
-        $default_value = null
534
-    ): EE_Serialized_Text_Field {
535
-        return $this->loader->getNew(
536
-            'EE_Serialized_Text_Field',
537
-            [$table_column, $nice_name, $nullable, $default_value]
538
-        );
539
-    }
540
-
541
-
542
-    /**
543
-     * @param string $table_column
544
-     * @param string $nice_name
545
-     * @param bool   $nullable
546
-     * @param null   $default_value
547
-     * @return EE_Simple_HTML_Field
548
-     */
549
-    public function createSimpleHtmlField(
550
-        string $table_column,
551
-        string $nice_name,
552
-        bool $nullable,
553
-        $default_value = null
554
-    ): EE_Simple_HTML_Field {
555
-        return $this->loader->getNew(
556
-            'EE_Simple_HTML_Field',
557
-            [$table_column, $nice_name, $nullable, $default_value]
558
-        );
559
-    }
560
-
561
-
562
-    /**
563
-     * @param string $table_column
564
-     * @param string $nice_name
565
-     * @param bool   $nullable
566
-     * @param null   $default_value
567
-     * @return EE_Slug_Field
568
-     */
569
-    public function createSlugField(
570
-        string $table_column,
571
-        string $nice_name,
572
-        bool $nullable = false,
573
-        $default_value = null
574
-    ): EE_Slug_Field {
575
-        return $this->loader->getNew(
576
-            'EE_Slug_Field',
577
-            [$table_column, $nice_name, $nullable, $default_value]
578
-        );
579
-    }
580
-
581
-
582
-    /**
583
-     * @param string $table_column
584
-     * @param string $nice_name
585
-     * @param bool   $nullable
586
-     * @param null   $default_value
587
-     * @return EE_Trashed_Flag_Field
588
-     */
589
-    public function createTrashedFlagField(
590
-        string $table_column,
591
-        string $nice_name,
592
-        bool $nullable,
593
-        $default_value = null
594
-    ): EE_Trashed_Flag_Field {
595
-        return $this->loader->getNew(
596
-            'EE_Trashed_Flag_Field',
597
-            [$table_column, $nice_name, $nullable, $default_value]
598
-        );
599
-    }
600
-
601
-
602
-    /**
603
-     * @param string $table_column
604
-     * @param string $nice_name
605
-     * @param bool   $nullable
606
-     * @param mixed  $default_value
607
-     * @param array $values     If additional statuses are to be used other than the default WP statuses,
608
-     *                          then they can be registered via this property.
609
-     *                          The format of the array should be as follows:
610
-     *                          [
611
-     *                              'status_reference' => [
612
-     *                                  'label' => __('Status Reference Label', 'event_espresso'),
613
-     *                                  // whether status is shown on the frontend of the site
614
-     *                                  'public' => true,
615
-     *                                  // whether status is excluded from wp searches
616
-     *                                  'exclude_from_search' => false,
617
-     *                                  // whether status is included in queries
618
-     *                                  for the admin 'all' view in list table views.
619
-     *                                  'show_in_admin_all_list' => true,
620
-     *                                  // show in the list of statuses with post counts
621
-     *                                  // at the top of the admin list tables (i.e. Status Reference(2) )
622
-     *                                  'show_in_admin_status_list' => true,
623
-     *                                  // the text to display on the admin screen
624
-     *                                  // ( or you won't see your status count )
625
-     *                                  'label_count' => _n_noop(
626
-     *                                      'Status Reference <span class="count">(%s)</span>',
627
-     *                                      'Status References <span class="count">(%s)</span>'
628
-     *                                  ),
629
-     *                              ]
630
-     *                          ]
631
-     * @return EE_WP_Post_Status_Field
632
-     * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
633
-     */
634
-    public function createWpPostStatusField(
635
-        string $table_column,
636
-        string $nice_name,
637
-        bool $nullable,
638
-        $default_value = null,
639
-        array $values = []
640
-    ): EE_WP_Post_Status_Field {
641
-        return $this->loader->getNew(
642
-            'EE_WP_Post_Status_Field',
643
-            [$table_column, $nice_name, $nullable, $default_value, $values]
644
-        );
645
-    }
646
-
647
-
648
-    /**
649
-     * @param string $post_type
650
-     * @return EE_WP_Post_Type_Field
651
-     */
652
-    public function createWpPostTypeField(string $post_type): EE_WP_Post_Type_Field
653
-    {
654
-        return $this->loader->getNew('EE_WP_Post_Type_Field', [$post_type]);
655
-    }
656
-
657
-
658
-    /**
659
-     * @param string $table_column
660
-     * @param string $nice_name
661
-     * @param bool   $nullable
662
-     * @return EE_WP_User_Field
663
-     */
664
-    public function createWpUserField(string $table_column, string $nice_name, bool $nullable): EE_WP_User_Field
665
-    {
666
-        return $this->loader->getNew('EE_WP_User_Field', [$table_column, $nice_name, $nullable]);
667
-    }
49
+	/**
50
+	 * @var LoaderInterface $loader
51
+	 */
52
+	private $loader;
53
+
54
+
55
+	/**
56
+	 * ModelFieldFactory constructor.
57
+	 *
58
+	 * @param LoaderInterface $loader
59
+	 */
60
+	public function __construct(LoaderInterface $loader)
61
+	{
62
+		$this->loader = $loader;
63
+	}
64
+
65
+
66
+	/**
67
+	 * @param string $table_column
68
+	 * @param string $nice_name
69
+	 * @param bool   $nullable
70
+	 * @param null   $default_value
71
+	 * @return EE_All_Caps_Text_Field
72
+	 */
73
+	public function createAllCapsTextField(
74
+		string $table_column,
75
+		string $nice_name,
76
+		bool $nullable,
77
+		$default_value = null
78
+	): EE_All_Caps_Text_Field {
79
+		return $this->loader->getNew(
80
+			'EE_All_Caps_Text_Field',
81
+			[$table_column, $nice_name, $nullable, $default_value]
82
+		);
83
+	}
84
+
85
+
86
+	/**
87
+	 * @param string $table_column
88
+	 * @param string $nice_name
89
+	 * @param bool   $nullable
90
+	 * @param null   $default_value
91
+	 * @param string $model_name
92
+	 * @return EE_Any_Foreign_Model_Name_Field
93
+	 */
94
+	public function createAnyForeignModelNameField(
95
+		string $table_column,
96
+		string $nice_name,
97
+		bool $nullable,
98
+		$default_value = null,
99
+		string $model_name = ''
100
+	): EE_Any_Foreign_Model_Name_Field {
101
+		return $this->loader->getNew(
102
+			'EE_Any_Foreign_Model_Name_Field',
103
+			[$table_column, $nice_name, $nullable, $default_value, $model_name]
104
+		);
105
+	}
106
+
107
+
108
+	/**
109
+	 * @param string $table_column
110
+	 * @param string $nice_name
111
+	 * @param bool   $nullable
112
+	 * @param null   $default_value
113
+	 * @return EE_Boolean_Field
114
+	 */
115
+	public function createBooleanField(
116
+		string $table_column,
117
+		string $nice_name,
118
+		bool $nullable,
119
+		$default_value = null
120
+	): EE_Boolean_Field {
121
+		return $this->loader->getNew(
122
+			'EE_Boolean_Field',
123
+			[$table_column, $nice_name, $nullable, $default_value]
124
+		);
125
+	}
126
+
127
+
128
+	/**
129
+	 * @param string $table_column
130
+	 * @param string $nice_name
131
+	 * @param bool   $nullable
132
+	 * @param string $default_value
133
+	 * @param string $timezone_string
134
+	 * @return EE_Datetime_Field
135
+	 */
136
+	public function createDatetimeField(
137
+		string $table_column,
138
+		string $nice_name,
139
+		bool $nullable = false,
140
+		string $default_value = EE_Datetime_Field::now,
141
+		string $timezone_string = ''
142
+	): EE_Datetime_Field {
143
+		return $this->loader->getNew(
144
+			'EE_Datetime_Field',
145
+			[$table_column, $nice_name, $nullable, $default_value, $timezone_string]
146
+		);
147
+	}
148
+
149
+
150
+	/**
151
+	 * @param string $table_column
152
+	 * @param string $nice_name
153
+	 * @param bool   $nullable
154
+	 * @param null   $default_value
155
+	 * @return EE_DB_Only_Float_Field
156
+	 */
157
+	public function createDbOnlyFloatField(
158
+		string $table_column,
159
+		string $nice_name,
160
+		bool $nullable,
161
+		$default_value = null
162
+	): EE_DB_Only_Float_Field {
163
+		return $this->loader->getNew(
164
+			'EE_DB_Only_Float_Field',
165
+			[$table_column, $nice_name, $nullable, $default_value]
166
+		);
167
+	}
168
+
169
+
170
+	/**
171
+	 * @param string $table_column
172
+	 * @param string $nice_name
173
+	 * @param bool   $nullable
174
+	 * @param null   $default_value
175
+	 * @return EE_DB_Only_Int_Field
176
+	 */
177
+	public function createDbOnlyIntField(
178
+		string $table_column,
179
+		string $nice_name,
180
+		bool $nullable,
181
+		$default_value = null
182
+	): EE_DB_Only_Int_Field {
183
+		return $this->loader->getNew(
184
+			'EE_DB_Only_Int_Field',
185
+			[$table_column, $nice_name, $nullable, $default_value]
186
+		);
187
+	}
188
+
189
+
190
+	/**
191
+	 * @param string $table_column
192
+	 * @param string $nice_name
193
+	 * @param bool   $nullable
194
+	 * @param null   $default_value
195
+	 * @return EE_DB_Only_Text_Field
196
+	 */
197
+	public function createDbOnlyTextField(
198
+		string $table_column,
199
+		string $nice_name,
200
+		bool $nullable,
201
+		$default_value = null
202
+	): EE_DB_Only_Text_Field {
203
+		return $this->loader->getNew(
204
+			'EE_DB_Only_Text_Field',
205
+			[$table_column, $nice_name, $nullable, $default_value]
206
+		);
207
+	}
208
+
209
+
210
+	/**
211
+	 * @param string      $table_column
212
+	 * @param string      $nice_name
213
+	 * @param bool        $nullable
214
+	 * @param string|null $default_value
215
+	 * @return EE_Email_Field
216
+	 */
217
+	public function createEmailField(
218
+		string $table_column,
219
+		string $nice_name,
220
+		bool $nullable = true,
221
+		string $default_value = ''
222
+	): EE_Email_Field {
223
+		return $this->loader->getNew(
224
+			'EE_Email_Field',
225
+			[$table_column, $nice_name, $nullable, $default_value]
226
+		);
227
+	}
228
+
229
+
230
+	/**
231
+	 * @param string $table_column
232
+	 * @param string $nice_name
233
+	 * @param bool   $nullable
234
+	 * @param null   $default_value
235
+	 * @param array  $allowed_enum_values keys are values to be used in the DB,
236
+	 *                                    values are how they should be displayed
237
+	 * @return EE_Enum_Integer_Field
238
+	 */
239
+	public function createEnumIntegerField(
240
+		string $table_column,
241
+		string $nice_name,
242
+		bool $nullable,
243
+		$default_value = null,
244
+		array $allowed_enum_values = []
245
+	): EE_Enum_Integer_Field {
246
+		return $this->loader->getNew(
247
+			'EE_Enum_Integer_Field',
248
+			[$table_column, $nice_name, $nullable, $default_value, $allowed_enum_values]
249
+		);
250
+	}
251
+
252
+
253
+	/**
254
+	 * @param string $table_column
255
+	 * @param string $nice_name
256
+	 * @param bool   $nullable
257
+	 * @param null   $default_value
258
+	 * @param array  $allowed_enum_values keys are values to be used in the DB,
259
+	 *                                    values are how they should be displayed
260
+	 * @return EE_Enum_Text_Field
261
+	 */
262
+	public function createEnumTextField(
263
+		string $table_column,
264
+		string $nice_name,
265
+		bool $nullable,
266
+		$default_value,
267
+		array $allowed_enum_values
268
+	): EE_Enum_Text_Field {
269
+		return $this->loader->getNew(
270
+			'EE_Enum_Text_Field',
271
+			[$table_column, $nice_name, $nullable, $default_value, $allowed_enum_values]
272
+		);
273
+	}
274
+
275
+
276
+	/**
277
+	 * @param string $table_column
278
+	 * @param string $nice_name
279
+	 * @param bool   $nullable
280
+	 * @param null   $default_value
281
+	 * @return EE_Float_Field
282
+	 */
283
+	public function createFloatField(
284
+		string $table_column,
285
+		string $nice_name,
286
+		bool $nullable,
287
+		$default_value = null
288
+	): EE_Float_Field {
289
+		return $this->loader->getNew(
290
+			'EE_Float_Field',
291
+			[$table_column, $nice_name, $nullable, $default_value]
292
+		);
293
+	}
294
+
295
+
296
+	/**
297
+	 * @param string $table_column
298
+	 * @param string $nice_name
299
+	 * @param bool   $nullable
300
+	 * @param null   $default_value
301
+	 * @param string $model_name
302
+	 * @return EE_Foreign_Key_Int_Field
303
+	 */
304
+	public function createForeignKeyIntField(
305
+		string $table_column,
306
+		string $nice_name,
307
+		bool $nullable,
308
+		$default_value,
309
+		string $model_name
310
+	): EE_Foreign_Key_Int_Field {
311
+		return $this->loader->getNew(
312
+			'EE_Foreign_Key_Int_Field',
313
+			[$table_column, $nice_name, $nullable, $default_value, $model_name]
314
+		);
315
+	}
316
+
317
+
318
+	/**
319
+	 * @param string $table_column
320
+	 * @param string $nice_name
321
+	 * @param bool   $nullable
322
+	 * @param null   $default_value
323
+	 * @param string $model_name
324
+	 * @return EE_Foreign_Key_String_Field
325
+	 */
326
+	public function createForeignKeyStringField(
327
+		string $table_column,
328
+		string $nice_name,
329
+		bool $nullable,
330
+		$default_value,
331
+		string $model_name
332
+	): EE_Foreign_Key_String_Field {
333
+		return $this->loader->getNew(
334
+			'EE_Foreign_Key_String_Field',
335
+			[$table_column, $nice_name, $nullable, $default_value, $model_name]
336
+		);
337
+	}
338
+
339
+
340
+	/**
341
+	 * @param string $table_column
342
+	 * @param string $nice_name
343
+	 * @param bool   $nullable
344
+	 * @param null   $default_value
345
+	 * @return EE_Full_HTML_Field
346
+	 */
347
+	public function createFullHtmlField(
348
+		string $table_column,
349
+		string $nice_name,
350
+		bool $nullable,
351
+		$default_value = null
352
+	): EE_Full_HTML_Field {
353
+		return $this->loader->getNew(
354
+			'EE_Full_HTML_Field',
355
+			[$table_column, $nice_name, $nullable, $default_value]
356
+		);
357
+	}
358
+
359
+
360
+	/**
361
+	 * @param string $table_column
362
+	 * @param string $nice_name
363
+	 * @param bool   $nullable
364
+	 * @param null   $default_value
365
+	 * @return EE_Infinite_Integer_Field
366
+	 */
367
+	public function createInfiniteIntegerField(
368
+		string $table_column,
369
+		string $nice_name,
370
+		bool $nullable,
371
+		$default_value = null
372
+	): EE_Infinite_Integer_Field {
373
+		return $this->loader->getNew(
374
+			'EE_Infinite_Integer_Field',
375
+			[$table_column, $nice_name, $nullable, $default_value]
376
+		);
377
+	}
378
+
379
+
380
+	/**
381
+	 * @param string  $table_column
382
+	 * @param string  $nice_name
383
+	 * @param bool    $nullable
384
+	 * @param integer $default_value
385
+	 * @return EE_Integer_Field
386
+	 */
387
+	public function createIntegerField(
388
+		string $table_column,
389
+		string $nice_name,
390
+		bool $nullable = false,
391
+		int $default_value = 0
392
+	): EE_Integer_Field {
393
+		return $this->loader->getNew(
394
+			'EE_Integer_Field',
395
+			[$table_column, $nice_name, $nullable, $default_value]
396
+		);
397
+	}
398
+
399
+
400
+	/**
401
+	 * @param string $table_column
402
+	 * @param string $nice_name
403
+	 * @param bool   $nullable
404
+	 * @param null   $default_value
405
+	 * @return EE_Maybe_Serialized_Simple_HTML_Field
406
+	 */
407
+	public function createMaybeSerializedSimpleHtmlField(
408
+		string $table_column,
409
+		string $nice_name,
410
+		bool $nullable,
411
+		$default_value = null
412
+	): EE_Maybe_Serialized_Simple_HTML_Field {
413
+		return $this->loader->getNew(
414
+			'EE_Maybe_Serialized_Simple_HTML_Field',
415
+			[$table_column, $nice_name, $nullable, $default_value]
416
+		);
417
+	}
418
+
419
+
420
+	/**
421
+	 * @param string $table_column
422
+	 * @param string $nice_name
423
+	 * @param bool   $nullable
424
+	 * @param null   $default_value
425
+	 * @return EE_Maybe_Serialized_Text_Field
426
+	 */
427
+	public function createMaybeSerializedTextField(
428
+		string $table_column,
429
+		string $nice_name,
430
+		bool $nullable,
431
+		$default_value = null
432
+	): EE_Maybe_Serialized_Text_Field {
433
+		return $this->loader->getNew(
434
+			'EE_Maybe_Serialized_Text_Field',
435
+			[$table_column, $nice_name, $nullable, $default_value]
436
+		);
437
+	}
438
+
439
+
440
+	/**
441
+	 * @param string $table_column
442
+	 * @param string $nice_name
443
+	 * @param bool   $nullable
444
+	 * @param null   $default_value
445
+	 * @return EE_Money_Field
446
+	 */
447
+	public function createMoneyField(
448
+		string $table_column,
449
+		string $nice_name,
450
+		bool $nullable,
451
+		$default_value = null
452
+	): EE_Money_Field {
453
+		return $this->loader->getNew(
454
+			'EE_Money_Field',
455
+			[$table_column, $nice_name, $nullable, $default_value]
456
+		);
457
+	}
458
+
459
+
460
+	/**
461
+	 * @param string $table_column
462
+	 * @param string $nice_name
463
+	 * @param bool   $nullable
464
+	 * @param string $default_value
465
+	 * @return EE_Plain_Text_Field
466
+	 */
467
+	public function createPlainTextField(
468
+		string $table_column,
469
+		string $nice_name,
470
+		bool $nullable = true,
471
+		string $default_value = ''
472
+	): EE_Plain_Text_Field {
473
+		return $this->loader->getNew(
474
+			'EE_Plain_Text_Field',
475
+			[$table_column, $nice_name, $nullable, $default_value]
476
+		);
477
+	}
478
+
479
+
480
+	/**
481
+	 * @param string $table_column
482
+	 * @param string $nice_name
483
+	 * @param bool   $nullable
484
+	 * @param null   $default_value
485
+	 * @return EE_Post_Content_Field
486
+	 */
487
+	public function createPostContentField(
488
+		string $table_column,
489
+		string $nice_name,
490
+		bool $nullable,
491
+		$default_value = null
492
+	): EE_Post_Content_Field {
493
+		return $this->loader->getNew(
494
+			'EE_Post_Content_Field',
495
+			[$table_column, $nice_name, $nullable, $default_value]
496
+		);
497
+	}
498
+
499
+
500
+	/**
501
+	 * @param string $table_column
502
+	 * @param string $nice_name
503
+	 * @return EE_Primary_Key_Int_Field
504
+	 */
505
+	public function createPrimaryKeyIntField(string $table_column, string $nice_name): EE_Primary_Key_Int_Field
506
+	{
507
+		return $this->loader->getNew('EE_Primary_Key_Int_Field', [$table_column, $nice_name]);
508
+	}
509
+
510
+
511
+	/**
512
+	 * @param string $table_column
513
+	 * @param string $nice_name
514
+	 * @return EE_Primary_Key_String_Field
515
+	 */
516
+	public function createPrimaryKeyStringField(string $table_column, string $nice_name): EE_Primary_Key_String_Field
517
+	{
518
+		return $this->loader->getNew('EE_Primary_Key_String_Field', [$table_column, $nice_name]);
519
+	}
520
+
521
+
522
+	/**
523
+	 * @param string $table_column
524
+	 * @param string $nice_name
525
+	 * @param bool   $nullable
526
+	 * @param null   $default_value
527
+	 * @return EE_Serialized_Text_Field
528
+	 */
529
+	public function createSerializedTextField(
530
+		string $table_column,
531
+		string $nice_name,
532
+		bool $nullable,
533
+		$default_value = null
534
+	): EE_Serialized_Text_Field {
535
+		return $this->loader->getNew(
536
+			'EE_Serialized_Text_Field',
537
+			[$table_column, $nice_name, $nullable, $default_value]
538
+		);
539
+	}
540
+
541
+
542
+	/**
543
+	 * @param string $table_column
544
+	 * @param string $nice_name
545
+	 * @param bool   $nullable
546
+	 * @param null   $default_value
547
+	 * @return EE_Simple_HTML_Field
548
+	 */
549
+	public function createSimpleHtmlField(
550
+		string $table_column,
551
+		string $nice_name,
552
+		bool $nullable,
553
+		$default_value = null
554
+	): EE_Simple_HTML_Field {
555
+		return $this->loader->getNew(
556
+			'EE_Simple_HTML_Field',
557
+			[$table_column, $nice_name, $nullable, $default_value]
558
+		);
559
+	}
560
+
561
+
562
+	/**
563
+	 * @param string $table_column
564
+	 * @param string $nice_name
565
+	 * @param bool   $nullable
566
+	 * @param null   $default_value
567
+	 * @return EE_Slug_Field
568
+	 */
569
+	public function createSlugField(
570
+		string $table_column,
571
+		string $nice_name,
572
+		bool $nullable = false,
573
+		$default_value = null
574
+	): EE_Slug_Field {
575
+		return $this->loader->getNew(
576
+			'EE_Slug_Field',
577
+			[$table_column, $nice_name, $nullable, $default_value]
578
+		);
579
+	}
580
+
581
+
582
+	/**
583
+	 * @param string $table_column
584
+	 * @param string $nice_name
585
+	 * @param bool   $nullable
586
+	 * @param null   $default_value
587
+	 * @return EE_Trashed_Flag_Field
588
+	 */
589
+	public function createTrashedFlagField(
590
+		string $table_column,
591
+		string $nice_name,
592
+		bool $nullable,
593
+		$default_value = null
594
+	): EE_Trashed_Flag_Field {
595
+		return $this->loader->getNew(
596
+			'EE_Trashed_Flag_Field',
597
+			[$table_column, $nice_name, $nullable, $default_value]
598
+		);
599
+	}
600
+
601
+
602
+	/**
603
+	 * @param string $table_column
604
+	 * @param string $nice_name
605
+	 * @param bool   $nullable
606
+	 * @param mixed  $default_value
607
+	 * @param array $values     If additional statuses are to be used other than the default WP statuses,
608
+	 *                          then they can be registered via this property.
609
+	 *                          The format of the array should be as follows:
610
+	 *                          [
611
+	 *                              'status_reference' => [
612
+	 *                                  'label' => __('Status Reference Label', 'event_espresso'),
613
+	 *                                  // whether status is shown on the frontend of the site
614
+	 *                                  'public' => true,
615
+	 *                                  // whether status is excluded from wp searches
616
+	 *                                  'exclude_from_search' => false,
617
+	 *                                  // whether status is included in queries
618
+	 *                                  for the admin 'all' view in list table views.
619
+	 *                                  'show_in_admin_all_list' => true,
620
+	 *                                  // show in the list of statuses with post counts
621
+	 *                                  // at the top of the admin list tables (i.e. Status Reference(2) )
622
+	 *                                  'show_in_admin_status_list' => true,
623
+	 *                                  // the text to display on the admin screen
624
+	 *                                  // ( or you won't see your status count )
625
+	 *                                  'label_count' => _n_noop(
626
+	 *                                      'Status Reference <span class="count">(%s)</span>',
627
+	 *                                      'Status References <span class="count">(%s)</span>'
628
+	 *                                  ),
629
+	 *                              ]
630
+	 *                          ]
631
+	 * @return EE_WP_Post_Status_Field
632
+	 * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
633
+	 */
634
+	public function createWpPostStatusField(
635
+		string $table_column,
636
+		string $nice_name,
637
+		bool $nullable,
638
+		$default_value = null,
639
+		array $values = []
640
+	): EE_WP_Post_Status_Field {
641
+		return $this->loader->getNew(
642
+			'EE_WP_Post_Status_Field',
643
+			[$table_column, $nice_name, $nullable, $default_value, $values]
644
+		);
645
+	}
646
+
647
+
648
+	/**
649
+	 * @param string $post_type
650
+	 * @return EE_WP_Post_Type_Field
651
+	 */
652
+	public function createWpPostTypeField(string $post_type): EE_WP_Post_Type_Field
653
+	{
654
+		return $this->loader->getNew('EE_WP_Post_Type_Field', [$post_type]);
655
+	}
656
+
657
+
658
+	/**
659
+	 * @param string $table_column
660
+	 * @param string $nice_name
661
+	 * @param bool   $nullable
662
+	 * @return EE_WP_User_Field
663
+	 */
664
+	public function createWpUserField(string $table_column, string $nice_name, bool $nullable): EE_WP_User_Field
665
+	{
666
+		return $this->loader->getNew('EE_WP_User_Field', [$table_column, $nice_name, $nullable]);
667
+	}
668 668
 }
Please login to merge, or discard this patch.
core/services/graphql/interfaces/GraphQLInterface.php 2 patches
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -10,82 +10,82 @@
 block discarded – undo
10 10
 
11 11
 abstract class GraphQLInterface implements GraphQLInterfaceInterface
12 12
 {
13
-    protected string $namespace = 'Espresso';
14
-
15
-    protected string $name;
16
-
17
-    protected FieldResolverV2 $resolver;
18
-
19
-    /**
20
-     * @var GraphQLFieldInterface[]
21
-     */
22
-    protected array $fields;
23
-
24
-    public function __construct()
25
-    {
26
-        $this->name = $this->namespace . $this->getShortName();
27
-
28
-        $this->validateFields($this->getArrayOfFields());
29
-
30
-        $this->fields = $this->getArrayOfFields();
31
-
32
-        $this->resolver = new FieldResolverV2($this->getArrayOfFields());
33
-    }
34
-
35
-    public function getName(): string
36
-    {
37
-        return $this->name;
38
-    }
39
-
40
-    public function getDescription(): string
41
-    {
42
-        return '';
43
-    }
44
-
45
-    /**
46
-     * @return GraphQLFieldInterface[]
47
-     */
48
-    public function getFields(): array
49
-    {
50
-        return $this->fields;
51
-    }
52
-
53
-    /**
54
-     * Get GraphQL interface name *without* namespace prefix
55
-     */
56
-    abstract protected function getShortName(): string;
57
-
58
-    /**
59
-     * @return GraphQLFieldInterface[]
60
-     */
61
-    abstract protected function getArrayOfFields(): array;
62
-
63
-    /**
64
-     * @param mixed[] $array
65
-     * @return GraphQLFieldInterface[]
66
-     */
67
-    protected function validateFields(array $array): array
68
-    {
69
-        foreach ($array as $field) {
70
-            if (! ($field instanceof GraphQLFieldInterface)) {
71
-                throw new RuntimeException(
72
-                    sprintf(
73
-                        esc_html__(
74
-                            'GraphQL interface %1$s expects its fields to be instance of %2$s',
75
-                            'event_espresso'
76
-                        ),
77
-                        $this->name,
78
-                        GraphQLFieldInterface::class
79
-                    )
80
-                );
81
-            }
82
-        }
83
-
84
-        return $array;
85
-    }
86
-
87
-    public function resolveField($source, array $args, AppContext $context, ResolveInfo $info)
88
-    {
89
-        return $this->resolver->resolve($source, $args, $context, $info);
90
-    }
13
+	protected string $namespace = 'Espresso';
14
+
15
+	protected string $name;
16
+
17
+	protected FieldResolverV2 $resolver;
18
+
19
+	/**
20
+	 * @var GraphQLFieldInterface[]
21
+	 */
22
+	protected array $fields;
23
+
24
+	public function __construct()
25
+	{
26
+		$this->name = $this->namespace . $this->getShortName();
27
+
28
+		$this->validateFields($this->getArrayOfFields());
29
+
30
+		$this->fields = $this->getArrayOfFields();
31
+
32
+		$this->resolver = new FieldResolverV2($this->getArrayOfFields());
33
+	}
34
+
35
+	public function getName(): string
36
+	{
37
+		return $this->name;
38
+	}
39
+
40
+	public function getDescription(): string
41
+	{
42
+		return '';
43
+	}
44
+
45
+	/**
46
+	 * @return GraphQLFieldInterface[]
47
+	 */
48
+	public function getFields(): array
49
+	{
50
+		return $this->fields;
51
+	}
52
+
53
+	/**
54
+	 * Get GraphQL interface name *without* namespace prefix
55
+	 */
56
+	abstract protected function getShortName(): string;
57
+
58
+	/**
59
+	 * @return GraphQLFieldInterface[]
60
+	 */
61
+	abstract protected function getArrayOfFields(): array;
62
+
63
+	/**
64
+	 * @param mixed[] $array
65
+	 * @return GraphQLFieldInterface[]
66
+	 */
67
+	protected function validateFields(array $array): array
68
+	{
69
+		foreach ($array as $field) {
70
+			if (! ($field instanceof GraphQLFieldInterface)) {
71
+				throw new RuntimeException(
72
+					sprintf(
73
+						esc_html__(
74
+							'GraphQL interface %1$s expects its fields to be instance of %2$s',
75
+							'event_espresso'
76
+						),
77
+						$this->name,
78
+						GraphQLFieldInterface::class
79
+					)
80
+				);
81
+			}
82
+		}
83
+
84
+		return $array;
85
+	}
86
+
87
+	public function resolveField($source, array $args, AppContext $context, ResolveInfo $info)
88
+	{
89
+		return $this->resolver->resolve($source, $args, $context, $info);
90
+	}
91 91
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 
24 24
     public function __construct()
25 25
     {
26
-        $this->name = $this->namespace . $this->getShortName();
26
+        $this->name = $this->namespace.$this->getShortName();
27 27
 
28 28
         $this->validateFields($this->getArrayOfFields());
29 29
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
     protected function validateFields(array $array): array
68 68
     {
69 69
         foreach ($array as $field) {
70
-            if (! ($field instanceof GraphQLFieldInterface)) {
70
+            if ( ! ($field instanceof GraphQLFieldInterface)) {
71 71
                 throw new RuntimeException(
72 72
                     sprintf(
73 73
                         esc_html__(
Please login to merge, or discard this patch.
core/services/graphql/connections/ConnectionInterface.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -16,19 +16,19 @@
 block discarded – undo
16 16
  */
17 17
 interface ConnectionInterface
18 18
 {
19
-    /**
20
-     * @return array
21
-     * @since 5.0.0.p
22
-     */
23
-    public function config();
19
+	/**
20
+	 * @return array
21
+	 * @since 5.0.0.p
22
+	 */
23
+	public function config();
24 24
 
25
-    /**
26
-     * @param EE_Base      $entity
27
-     * @param array        $args
28
-     * @param AppContext   $context
29
-     * @param ResolveInfo  $info
30
-     * @return array
31
-     * @since 5.0.0.p
32
-     */
33
-    public function resolveConnection($entity, $args, $context, $info);
25
+	/**
26
+	 * @param EE_Base      $entity
27
+	 * @param array        $args
28
+	 * @param AppContext   $context
29
+	 * @param ResolveInfo  $info
30
+	 * @return array
31
+	 * @since 5.0.0.p
32
+	 */
33
+	public function resolveConnection($entity, $args, $context, $info);
34 34
 }
Please login to merge, or discard this patch.
core/services/database/WordPressOption.php 1 patch
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -17,179 +17,179 @@
 block discarded – undo
17 17
  */
18 18
 abstract class WordPressOption
19 19
 {
20
-    public const NOT_SET_YET = 'wordpress-option-value-not-yet-set';
21
-
22
-    /**
23
-     * WordPress makes it difficult to determine if an option successfully saved or not,
24
-     * which is sometimes really important to know, especially if the information you are saving is critical.
25
-     * The following options allow us to have a better chance of knowing when an update actually failed
26
-     * or when everything is OK but it just didn't update because the value hasn't changed.
27
-     */
28
-    public const UPDATE_SUCCESS = 1;
29
-
30
-    public const UPDATE_NONE    = 0;
31
-
32
-    public const UPDATE_ERROR   = -1;
33
-
34
-    private bool $autoload = false;
35
-
36
-    /**
37
-     * @var mixed
38
-     */
39
-    private $default_value = null;
40
-
41
-    private string $option_name = '';
42
-
43
-    /**
44
-     * @var mixed
45
-     */
46
-    private $value = WordPressOption::NOT_SET_YET;
47
-
48
-    private OptionEngine $option_engine;
49
-
50
-
51
-    /**
52
-     * WordPressOption constructor.
53
-     *
54
-     * @param string $option_name
55
-     * @param mixed  $default_value
56
-     * @param bool   $autoload          if true, will load the option on EVERY request
57
-     * @param bool   $is_network_option if true, will save the option to the network as opposed to the current blog
58
-     */
59
-    public function __construct(
60
-        string $option_name,
61
-        $default_value,
62
-        bool $autoload = false,
63
-        bool $is_network_option = false
64
-    ) {
65
-        $this->setAutoload($autoload);
66
-        $this->setDefaultValue($default_value);
67
-        $this->setOptionName($option_name);
68
-        $this->option_engine = new OptionEngine($is_network_option);
69
-    }
70
-
71
-
72
-    /**
73
-     * @param bool|string $autoload
74
-     */
75
-    public function setAutoload($autoload): void
76
-    {
77
-        $this->autoload = filter_var($autoload, FILTER_VALIDATE_BOOLEAN);
78
-    }
79
-
80
-
81
-    /**
82
-     * @param mixed $default_value
83
-     */
84
-    public function setDefaultValue($default_value): void
85
-    {
86
-        $this->default_value = $default_value;
87
-    }
88
-
89
-
90
-    /**
91
-     * @param string $option_name
92
-     */
93
-    public function setOptionName(string $option_name): void
94
-    {
95
-        $this->option_name = sanitize_key($option_name);
96
-    }
97
-
98
-
99
-    /**
100
-     * @return string
101
-     */
102
-    public function optionExists(): string
103
-    {
104
-        return $this->option_engine->getOption(
105
-            $this->getOptionName(),
106
-            WordPressOption::NOT_SET_YET
107
-        ) !== WordPressOption::NOT_SET_YET;
108
-    }
109
-
110
-
111
-    /**
112
-     * @return string
113
-     */
114
-    public function getOptionName(): string
115
-    {
116
-        return $this->option_name;
117
-    }
118
-
119
-
120
-    /**
121
-     * @return false|mixed|void
122
-     */
123
-    public function loadOption()
124
-    {
125
-        if ($this->value === WordPressOption::NOT_SET_YET) {
126
-            $this->value = $this->option_engine->getOption($this->getOptionName(), null);
127
-            if ($this->value === null) {
128
-                $this->updateOption($this->default_value, true);
129
-            }
130
-        }
131
-        return $this->value;
132
-    }
133
-
134
-
135
-    /**
136
-     * @param $value
137
-     * @param bool $force_update
138
-     * @return int
139
-     */
140
-    public function updateOption($value, bool $force_update = false): int
141
-    {
142
-        // don't update if value has not changed since last update
143
-        if (! $force_update && $this->valueIsUnchanged($value)) {
144
-            return WordPressOption::UPDATE_NONE;
145
-        }
146
-        if ($force_update) {
147
-            $this->option_engine->updateOption($this->getOptionName(), null);
148
-        }
149
-        $this->value = $value;
150
-        // because the options for updating differ when adding an option for the first time
151
-        // we use the WordPressOption::NOT_SET_YET to determine if things already exist in the db
152
-        $updated = $this->optionExists()
153
-            ? $this->option_engine->updateOption($this->getOptionName(), $this->value)
154
-            : $this->option_engine->addOption($this->getOptionName(), $this->value, $this->autoload());
155
-
156
-        if ($updated) {
157
-            return WordPressOption::UPDATE_SUCCESS;
158
-        }
159
-        return WordPressOption::UPDATE_ERROR;
160
-    }
161
-
162
-
163
-    private function valueIsUnchanged($value): bool
164
-    {
165
-        if (is_array($value) && is_array($this->value)) {
166
-            $diff = EEH_Array::array_diff_recursive($value, $this->value);
167
-            // $diff = array_diff($value, $this->value);
168
-            return empty($diff);
169
-        }
170
-        // emulate WP's method for checking equality
171
-        return $value === $this->value && maybe_serialize($value) === maybe_serialize($this->value);
172
-    }
173
-
174
-
175
-    /**
176
-     * @return string
177
-     */
178
-    private function autoload(): string
179
-    {
180
-        return $this->autoload ? 'yes' : 'no';
181
-    }
182
-
183
-
184
-    /**
185
-     * Deletes the option from the database
186
-     * for the rest of the request
187
-     *
188
-     * @return bool
189
-     * @since  5.0.0.p
190
-     */
191
-    public function deleteOption(): bool
192
-    {
193
-        return $this->option_engine->deleteOption($this->getOptionName());
194
-    }
20
+	public const NOT_SET_YET = 'wordpress-option-value-not-yet-set';
21
+
22
+	/**
23
+	 * WordPress makes it difficult to determine if an option successfully saved or not,
24
+	 * which is sometimes really important to know, especially if the information you are saving is critical.
25
+	 * The following options allow us to have a better chance of knowing when an update actually failed
26
+	 * or when everything is OK but it just didn't update because the value hasn't changed.
27
+	 */
28
+	public const UPDATE_SUCCESS = 1;
29
+
30
+	public const UPDATE_NONE    = 0;
31
+
32
+	public const UPDATE_ERROR   = -1;
33
+
34
+	private bool $autoload = false;
35
+
36
+	/**
37
+	 * @var mixed
38
+	 */
39
+	private $default_value = null;
40
+
41
+	private string $option_name = '';
42
+
43
+	/**
44
+	 * @var mixed
45
+	 */
46
+	private $value = WordPressOption::NOT_SET_YET;
47
+
48
+	private OptionEngine $option_engine;
49
+
50
+
51
+	/**
52
+	 * WordPressOption constructor.
53
+	 *
54
+	 * @param string $option_name
55
+	 * @param mixed  $default_value
56
+	 * @param bool   $autoload          if true, will load the option on EVERY request
57
+	 * @param bool   $is_network_option if true, will save the option to the network as opposed to the current blog
58
+	 */
59
+	public function __construct(
60
+		string $option_name,
61
+		$default_value,
62
+		bool $autoload = false,
63
+		bool $is_network_option = false
64
+	) {
65
+		$this->setAutoload($autoload);
66
+		$this->setDefaultValue($default_value);
67
+		$this->setOptionName($option_name);
68
+		$this->option_engine = new OptionEngine($is_network_option);
69
+	}
70
+
71
+
72
+	/**
73
+	 * @param bool|string $autoload
74
+	 */
75
+	public function setAutoload($autoload): void
76
+	{
77
+		$this->autoload = filter_var($autoload, FILTER_VALIDATE_BOOLEAN);
78
+	}
79
+
80
+
81
+	/**
82
+	 * @param mixed $default_value
83
+	 */
84
+	public function setDefaultValue($default_value): void
85
+	{
86
+		$this->default_value = $default_value;
87
+	}
88
+
89
+
90
+	/**
91
+	 * @param string $option_name
92
+	 */
93
+	public function setOptionName(string $option_name): void
94
+	{
95
+		$this->option_name = sanitize_key($option_name);
96
+	}
97
+
98
+
99
+	/**
100
+	 * @return string
101
+	 */
102
+	public function optionExists(): string
103
+	{
104
+		return $this->option_engine->getOption(
105
+			$this->getOptionName(),
106
+			WordPressOption::NOT_SET_YET
107
+		) !== WordPressOption::NOT_SET_YET;
108
+	}
109
+
110
+
111
+	/**
112
+	 * @return string
113
+	 */
114
+	public function getOptionName(): string
115
+	{
116
+		return $this->option_name;
117
+	}
118
+
119
+
120
+	/**
121
+	 * @return false|mixed|void
122
+	 */
123
+	public function loadOption()
124
+	{
125
+		if ($this->value === WordPressOption::NOT_SET_YET) {
126
+			$this->value = $this->option_engine->getOption($this->getOptionName(), null);
127
+			if ($this->value === null) {
128
+				$this->updateOption($this->default_value, true);
129
+			}
130
+		}
131
+		return $this->value;
132
+	}
133
+
134
+
135
+	/**
136
+	 * @param $value
137
+	 * @param bool $force_update
138
+	 * @return int
139
+	 */
140
+	public function updateOption($value, bool $force_update = false): int
141
+	{
142
+		// don't update if value has not changed since last update
143
+		if (! $force_update && $this->valueIsUnchanged($value)) {
144
+			return WordPressOption::UPDATE_NONE;
145
+		}
146
+		if ($force_update) {
147
+			$this->option_engine->updateOption($this->getOptionName(), null);
148
+		}
149
+		$this->value = $value;
150
+		// because the options for updating differ when adding an option for the first time
151
+		// we use the WordPressOption::NOT_SET_YET to determine if things already exist in the db
152
+		$updated = $this->optionExists()
153
+			? $this->option_engine->updateOption($this->getOptionName(), $this->value)
154
+			: $this->option_engine->addOption($this->getOptionName(), $this->value, $this->autoload());
155
+
156
+		if ($updated) {
157
+			return WordPressOption::UPDATE_SUCCESS;
158
+		}
159
+		return WordPressOption::UPDATE_ERROR;
160
+	}
161
+
162
+
163
+	private function valueIsUnchanged($value): bool
164
+	{
165
+		if (is_array($value) && is_array($this->value)) {
166
+			$diff = EEH_Array::array_diff_recursive($value, $this->value);
167
+			// $diff = array_diff($value, $this->value);
168
+			return empty($diff);
169
+		}
170
+		// emulate WP's method for checking equality
171
+		return $value === $this->value && maybe_serialize($value) === maybe_serialize($this->value);
172
+	}
173
+
174
+
175
+	/**
176
+	 * @return string
177
+	 */
178
+	private function autoload(): string
179
+	{
180
+		return $this->autoload ? 'yes' : 'no';
181
+	}
182
+
183
+
184
+	/**
185
+	 * Deletes the option from the database
186
+	 * for the rest of the request
187
+	 *
188
+	 * @return bool
189
+	 * @since  5.0.0.p
190
+	 */
191
+	public function deleteOption(): bool
192
+	{
193
+		return $this->option_engine->deleteOption($this->getOptionName());
194
+	}
195 195
 }
Please login to merge, or discard this patch.
core/services/admin/AdminPageHeaderDecoratorInterface.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@
 block discarded – undo
12 12
  */
13 13
 interface AdminPageHeaderDecoratorInterface
14 14
 {
15
-    /**
16
-     * @param string $text
17
-     * @return string
18
-     * @since 4.10.2.p
19
-     */
20
-    public function getHeaderText(string $text = ''): string;
15
+	/**
16
+	 * @param string $text
17
+	 * @return string
18
+	 * @since 4.10.2.p
19
+	 */
20
+	public function getHeaderText(string $text = ''): string;
21 21
 }
Please login to merge, or discard this patch.
core/services/admin/AdminPageHeaderDecorator.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -15,16 +15,16 @@
 block discarded – undo
15 15
  */
16 16
 abstract class AdminPageHeaderDecorator implements AdminPageHeaderDecoratorInterface
17 17
 {
18
-    protected RequestInterface $request;
18
+	protected RequestInterface $request;
19 19
 
20 20
 
21
-    /**
22
-     * AdminPageHeader constructor.
23
-     *
24
-     * @param RequestInterface $request
25
-     */
26
-    public function __construct(RequestInterface $request)
27
-    {
28
-        $this->request = $request;
29
-    }
21
+	/**
22
+	 * AdminPageHeader constructor.
23
+	 *
24
+	 * @param RequestInterface $request
25
+	 */
26
+	public function __construct(RequestInterface $request)
27
+	{
28
+		$this->request = $request;
29
+	}
30 30
 }
Please login to merge, or discard this patch.