Completed
Branch BUG/11302/correct-error-messag... (694f28)
by
unknown
29:47 queued 12:21
created

EE_PMT_Base::__construct()   C

Complexity

Conditions 7
Paths 36

Size

Total Lines 32
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 21
nc 36
nop 1
dl 0
loc 32
rs 6.7272
c 0
b 0
f 0
1
<?php
2
EE_Registry::instance()->load_lib('Gateway');
3
EE_Registry::instance()->load_lib('Onsite_Gateway');
4
EE_Registry::instance()->load_lib('Offsite_Gateway');
5
6
use \EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter;
7
use \EventEspresso\core\services\formatters\AsciiOnly;
8
9
/**
10
 *
11
 * Class EE_PMT_Base
12
 *
13
 * Description
14
 *
15
 * @package            Event Espresso
16
 * @subpackage    core
17
 * @author                Mike Nelson
18
 * 
19
 *
20
 */
21
abstract class EE_PMT_Base
22
{
23
24
    const onsite = 'on-site';
25
    const offsite = 'off-site';
26
    const offline = 'off-line';
27
28
    /**
29
     * @var EE_Payment_Method
30
     */
31
    protected $_pm_instance = NULL;
32
33
    /**
34
     * @var boolean
35
     */
36
    protected $_requires_https = FALSE;
37
38
    /**
39
     * @var boolean
40
     */
41
    protected $_has_billing_form;
42
43
    /**
44
     * @var EE_Gateway
45
     */
46
    protected $_gateway = NULL;
47
48
    /**
49
     * @var EE_Payment_Method_Form
50
     */
51
    protected $_settings_form = NULL;
52
53
    /**
54
     * @var EE_Form_Section_Proper
55
     */
56
    protected $_billing_form = NULL;
57
58
    /**
59
     * @var boolean
60
     */
61
    protected $_cache_billing_form = TRUE;
62
63
    /**
64
     * String of the absolute path to the folder containing this file, with a trailing slash.
65
     * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/'
66
     * @var string
67
     */
68
    protected $_file_folder = NULL;
69
70
    /**
71
     * String to the absolute URL to this file (useful for getting its web-accessible resources
72
     * like images, js, or css)
73
     * @var string
74
     */
75
    protected $_file_url = NULL;
76
77
    /**
78
     * Pretty name for the payment method
79
     * @var string
80
     */
81
    protected $_pretty_name = NULL;
82
83
    /**
84
     *
85
     * @var string
86
     */
87
    protected $_default_button_url = NULL;
88
89
    /**
90
     *
91
     * @var string
92
     */
93
    protected $_default_description = NULL;
94
95
96
    /**
97
     *
98
     * @param EE_Payment_Method $pm_instance
99
     * @throws EE_Error
100
     * @return EE_PMT_Base
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
101
     */
102
    function __construct($pm_instance = NULL)
103
    {
104
        if ($pm_instance instanceof EE_Payment_Method) {
105
            $this->set_instance($pm_instance);
106
        }
107
        if ($this->_gateway) {
108
            $this->_gateway->set_payment_model(EEM_Payment::instance());
109
            $this->_gateway->set_payment_log(EEM_Change_Log::instance());
110
            $this->_gateway->set_template_helper(new EEH_Template());
111
            $this->_gateway->set_line_item_helper(new EEH_Line_Item());
112
            $this->_gateway->set_money_helper(new EEH_Money());
113
            $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
114
            $this->_gateway->set_unsupported_character_remover(new AsciiOnly());
115
            do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
116
        }
117
        if (!isset($this->_has_billing_form)) {
118
            // by default, On Site gateways have a billing form
119
            if ($this->payment_occurs() == EE_PMT_Base::onsite) {
120
                $this->set_has_billing_form(true);
121
            } else {
122
                $this->set_has_billing_form(false);
123
            }
124
        }
125
126
        if (!$this->_pretty_name) {
127
            throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso")));
128
        }
129
        //if the child didn't specify a default button, use the credit card one
130
        if ($this->_default_button_url === NULL) {
131
            $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png';
132
        }
133
    }
134
135
136
    /**
137
     * @param boolean $has_billing_form
138
     */
139
    public function set_has_billing_form($has_billing_form)
140
    {
141
        $this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN);
142
    }
143
144
145
    /**
146
     * sets the file_folder property
147
     */
148
    protected function _set_file_folder()
149
    {
150
        $reflector = new ReflectionClass(get_class($this));
151
        $fn = $reflector->getFileName();
152
        $this->_file_folder = dirname($fn) . DS;
153
    }
154
155
156
    /**
157
     * sets the file URL with a trailing slash for this PMT
158
     */
159
    protected function _set_file_url()
160
    {
161
        $plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR);
162
        $file_folder_fixed = str_replace('\\', DS, $this->file_folder());
163
        $file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed);
164
        $this->_file_url = $file_path;
165
    }
166
167
    /**
168
     * Gets the default description on all payment methods of this type
169
     * @return string
170
     */
171
    public function default_description()
172
    {
173
        return $this->_default_description;
174
    }
175
176
177
    /**
178
     * Returns the folder containing the PMT child class, with a trailing slash
179
     * @return string
180
     */
181
    public function file_folder()
182
    {
183
        if (!$this->_file_folder) {
184
            $this->_set_file_folder();
185
        }
186
        return $this->_file_folder;
187
    }
188
189
190
    /**
191
     * @return string
192
     */
193
    public function file_url()
194
    {
195
        if (!$this->_file_url) {
196
            $this->_set_file_url();
197
        }
198
        return $this->_file_url;
199
    }
200
201
202
    /**
203
     * Sets the payment method instance this payment method type is for.
204
     * Its important teh payment method instance is set before
205
     * @param EE_Payment_Method $payment_method_instance
206
     */
207
    function set_instance($payment_method_instance)
208
    {
209
        $this->_pm_instance = $payment_method_instance;
210
        //if they have already requested the settings form, make sure its
211
        //data matches this model object
212
        if ($this->_settings_form) {
213
            $this->settings_form()->populate_model_obj($payment_method_instance);
214
        }
215
        if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
216
            $this->_gateway->set_settings($payment_method_instance->settings_array());
217
        }
218
    }
219
220
221
    /**
222
     * Gets teh form for displaying to admins where they setup the payment method
223
     * @return EE_Payment_Method_Form
224
     */
225
    function settings_form()
226
    {
227
        if (!$this->_settings_form) {
228
            $this->_settings_form = $this->generate_new_settings_form();
229
            $this->_settings_form->set_payment_method_type($this);
230
            //if we have already assigned a model object to this pmt, make
231
            //sure its reflected in teh form we just generated
232
            if ($this->_pm_instance) {
233
                $this->_settings_form->populate_model_obj($this->_pm_instance);
234
            }
235
        }
236
        return $this->_settings_form;
237
    }
238
239
240
    /**
241
     * Gets the form for all the settings related to this payment method type
242
     * @return EE_Payment_Method_Form
243
     */
244
    abstract function generate_new_settings_form();
245
246
247
    /**
248
     * Sets the form for settings. This may be useful if we have already received
249
     * a form submission and have form data it in, and want to use it anytime we're showing
250
     * this payment method type's settings form later in the request
251
     * @param EE_Payment_Method_Form $form
252
     */
253
    public function set_settings_form($form)
254
    {
255
        $this->_settings_form = $form;
256
    }
257
258
259
    /**
260
     * @return boolean
261
     */
262
    public function has_billing_form()
263
    {
264
        return $this->_has_billing_form;
265
    }
266
267
268
    /**
269
     * Gets the form for displaying to attendees where they can enter their billing info
270
     * which will be sent to teh gateway (can be null)
271
     *
272
     * @param \EE_Transaction $transaction
273
     * @param array $extra_args
274
     * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null
275
     */
276
    public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array())
277
    {
278
        // has billing form already been regenerated ? or overwrite cache?
279
        if (!$this->_billing_form instanceof EE_Billing_Info_Form || !$this->_cache_billing_form) {
280
            $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
281
        }
282
        //if we know who the attendee is, and this is a billing form
283
        //that uses attendee info, populate it
284
        if (
285
        apply_filters(
286
            'FHEE__populate_billing_form_fields_from_attendee',
287
            (
288
                $this->_billing_form instanceof EE_Billing_Attendee_Info_Form
289
                && $transaction instanceof EE_Transaction
290
                && $transaction->primary_registration() instanceof EE_Registration
291
                && $transaction->primary_registration()->attendee() instanceof EE_Attendee
292
            ),
293
            $this->_billing_form,
294
            $transaction
295
        )
296
        ) {
297
            $this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee());
0 ignored issues
show
Bug introduced by
It seems like $transaction is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
298
        }
299
        return $this->_billing_form;
300
    }
301
302
303
    /**
304
     * Creates the billing form for this payment method type
305
     * @param \EE_Transaction $transaction
306
     * @return \EE_Billing_Info_Form
307
     */
308
    abstract function generate_new_billing_form(EE_Transaction $transaction = NULL);
309
310
311
    /**
312
     * apply_billing_form_debug_settings
313
     * applies debug data to the form
314
     *
315
     * @param \EE_Billing_Info_Form $billing_form
316
     * @return \EE_Billing_Info_Form
317
     */
318
    public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form)
319
    {
320
        return $billing_form;
321
    }
322
323
324
    /**
325
     * Sets the billing form for this payment method type. You may want to use this
326
     * if you have form
327
     * @param EE_Payment_Method $form
328
     */
329
    public function set_billing_form($form)
330
    {
331
        $this->_billing_form = $form;
332
    }
333
334
335
    /**
336
     * Returns whether or not this payment method requires HTTPS to be used
337
     * @return boolean
338
     */
339
    function requires_https()
340
    {
341
        return $this->_requires_https;
342
    }
343
344
345
    /**
346
     *
347
     * @param EE_Transaction $transaction
348
     * @param float $amount
349
     * @param EE_Billing_Info_Form $billing_info
350
     * @param string $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
     */
357
    function process_payment(EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null, $fail_url = '', $method = 'CART', $by_admin = false)
358
    {
359
        // @todo: add surcharge for the payment method, if any
360
        if ($this->_gateway) {
361
            //there is a gateway, so we're going to make a payment object
362
            //but wait! do they already have a payment in progress that we thought was failed?
363
            $duplicate_properties = array(
364
                'STS_ID' => EEM_Payment::status_id_failed,
365
                'TXN_ID' => $transaction->ID(),
366
                'PMD_ID' => $this->_pm_instance->ID(),
367
                'PAY_source' => $method,
368
                'PAY_amount' => $amount !== null ? $amount : $transaction->remaining(),
369
                'PAY_gateway_response' => null,
370
            );
371
            $payment = EEM_Payment::instance()->get_one(array($duplicate_properties));
372
            //if we didn't already have a payment in progress for the same thing,
373
            //then we actually want to make a new payment
374
            if (!$payment instanceof EE_Payment) {
375
                $payment = EE_Payment::new_instance(
376
                    array_merge(
377
                        $duplicate_properties,
378
                        array(
379
                            'PAY_timestamp' => time(),
380
                            'PAY_txn_id_chq_nmbr' => null,
381
                            'PAY_po_number' => null,
382
                            'PAY_extra_accntng' => null,
383
                            'PAY_details' => null,
384
                        )
385
                    )
386
                );
387
            }
388
            //make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it
389
            $payment->save();
390
            $billing_values = $this->_get_billing_values_from_form($billing_info);
0 ignored issues
show
Bug introduced by
It seems like $billing_info defined by parameter $billing_info on line 357 can be null; however, EE_PMT_Base::_get_billing_values_from_form() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
391
392
            //  Offsite Gateway
393
            if ($this->_gateway instanceof EE_Offsite_Gateway) {
394
395
                $payment = $this->_gateway->set_redirection_info(
396
                    $payment,
397
                    $billing_values,
398
                    $return_url,
399
                    EE_Config::instance()->core->txn_page_url(
400
                        array(
401
                            'e_reg_url_link' => $transaction->primary_registration()->reg_url_link(),
402
                            'ee_payment_method' => $this->_pm_instance->slug()
403
                        )
404
                    ),
405
                    $fail_url
406
                );
407
                $payment->save();
408
                //  Onsite Gateway
409
            } elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
410
411
                $payment = $this->_gateway->do_direct_payment($payment, $billing_values);
412
                $payment->save();
413
414
            } else {
415
                throw new EE_Error(
416
                    sprintf(
417
                        __('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)', 'event_espresso'),
418
                        get_class($this),
419
                        gettype($this->_gateway)
420
                    )
421
                );
422
            }
423
424
        } else {
425
            // no gateway provided
426
            // there is no payment. Must be an offline gateway
427
            // create a payment object anyways, but dont save it
428
            $payment = EE_Payment::new_instance(
429
                array(
430
                    'STS_ID' => EEM_Payment::status_id_pending,
431
                    'TXN_ID' => $transaction->ID(),
432
                    'PMD_ID' => $transaction->payment_method_ID(),
433
                    'PAY_amount' => 0.00,
434
                    'PAY_timestamp' => time(),
435
                )
436
            );
437
438
        }
439
440
        // if there is billing info, clean it and save it now
441
        if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
442
            $this->_save_billing_info_to_attendee($billing_info, $transaction);
443
        }
444
445
        return $payment;
446
    }
447
448
    /**
449
     * Gets the values we want to pass onto the gateway. Normally these
450
     * are just the 'pretty' values, but there may be times the data may need
451
     * a  little massaging. Proper subsections will become arrays of inputs
452
     * @param EE_Billing_Info_Form $billing_form
453
     * @return array
454
     */
455
    protected function _get_billing_values_from_form($billing_form)
456
    {
457
        if ($billing_form instanceof EE_Form_Section_Proper) {
458
            return $billing_form->input_pretty_values(true);
459
        } else {
460
            return NULL;
461
        }
462
    }
463
464
465
    /**
466
     * Handles an instant payment notification when the transaction is known (by default).
467
     * @param array $req_data
468
     * @param EE_Transaction $transaction
469
     * @return EE_Payment
470
     * @throws EE_Error
471
     */
472
    public function handle_ipn($req_data, $transaction)
473
    {
474
        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
475
        if (!$this->_gateway instanceof EE_Offsite_Gateway) {
476
            throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE)));
477
478
        }
479
        $payment = $this->_gateway->handle_payment_update($req_data, $transaction);
480
        return $payment;
481
    }
482
483
484
    /**
485
     * Saves the billing info onto the attendee of the primary registrant on this transaction, and
486
     * cleans it first.
487
     * @param EE_Billing_Attendee_Info_Form $billing_form
488
     * @param EE_Transaction $transaction
489
     * @return boolean success
490
     */
491
    protected function _save_billing_info_to_attendee($billing_form, $transaction)
492
    {
493 View Code Duplication
        if (!$transaction || !$transaction instanceof EE_Transaction) {
494
            EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
495
            return false;
496
        }
497
        $primary_reg = $transaction->primary_registration();
498
        if (!$primary_reg) {
499
            EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
500
            return false;
501
        }
502
        $attendee = $primary_reg->attendee();
503
        if (!$attendee) {
504
            EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
505
            return false;
506
        }
507
        return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
508
509
    }
510
511
512
    /**
513
     * Gets the payment this IPN is for. Children may often want to
514
     * override this to inspect the request
515
     * @param EE_Transaction $transaction
516
     * @param array $req_data
517
     * @return EE_Payment
518
     */
519
    protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array())
520
    {
521
        return $transaction->last_payment();
522
    }
523
524
525
    /**
526
     * In case generic code cannot provide the payment processor with a specific payment method
527
     * and transaction, it will try calling this method on each activate payment method.
528
     * If the payment method is able to identify the request as being for it, it should fetch
529
     * the payment its for and return it. If not, it should throw an EE_Error to indicate it cannot
530
     * handle the IPN
531
     * @param array $req_data
532
     * @return EE_Payment only if this payment method can find the info its needs from $req_data
533
     * and identifies the IPN as being for this payment method (not just fo ra payment method of this type)
534
     * @throws EE_Error
535
     */
536
    public function handle_unclaimed_ipn($req_data = array())
537
    {
538
        throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this)));
539
    }
540
541
542
    /**
543
     * Logic to be accomplished when the payment attempt is complete.
544
     * Most payment methods don't need to do anything at this point; but some, like Mijireh, do.
545
     * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from
546
     * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status
547
     * of the payment). Fed a transaction because it's always assumed to be the last payment that
548
     * we're dealing with. Returns that last payment (if there is one)
549
     *
550
     * @param EE_Transaction $transaction
551
     * @return EE_Payment
552
     */
553
    public function finalize_payment_for($transaction)
554
    {
555
        return $transaction->last_payment();
556
    }
557
558
559
    /**
560
     * Whether or not this payment method's gateway supports sending refund requests
561
     * @return boolean
562
     */
563
    public function supports_sending_refunds()
564
    {
565
        if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
566
            return $this->_gateway->supports_sending_refunds();
567
        } else {
568
            return false;
569
        }
570
    }
571
572
573
    /**
574
     *
575
     * @param EE_Payment $payment
576
     * @param array $refund_info
577
     * @throws EE_Error
578
     * @return EE_Payment
579
     */
580
    public function process_refund(EE_Payment $payment, $refund_info = array())
581
    {
582
        if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
583
            return $this->_gateway->do_direct_refund($payment, $refund_info);
584
        } else {
585
            throw new EE_Error(
586
                sprintf(
587
                    __('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'),
588
                    get_class($this)
589
                )
590
            );
591
        }
592
    }
593
594
595
    /**
596
     * Returns one the class's constants onsite,offsite, or offline, depending on this
597
     * payment method's gateway.
598
     * @return string
599
     * @throws EE_Error
600
     */
601
    public function payment_occurs()
602
    {
603
        if (!$this->_gateway) {
604
            return EE_PMT_Base::offline;
605
        } elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
606
            return EE_PMT_Base::onsite;
607
        } elseif ($this->_gateway instanceof EE_Offsite_Gateway) {
608
            return EE_PMT_Base::offsite;
609
        } else {
610
            throw new EE_Error(sprintf(__("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", "event_espresso"), get_class($this)));
611
        }
612
    }
613
614
615
    /**
616
     * For adding any html output ab ove the payment overview.
617
     * Many gateways won't want ot display anything, so this function just returns an empty string.
618
     * Other gateways may want to override this, such as offline gateways.
619
     * @param EE_Payment $payment
620
     * @return string
621
     */
622
    public function payment_overview_content(EE_Payment $payment)
623
    {
624
        return EEH_Template::display_template(EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true);
625
    }
626
627
628
    /**
629
     * @return array where keys are the help tab name,
630
     * values are: array {
631
     * @type string $title i18n name for the help tab
632
     * @type string $filename name of the file located in ./help_tabs/ (ie, in a folder next to this file)
633
     * @type array $template_args any arguments you want passed to the template file while rendering.
634
     *                Keys will be variable names and values with be their values.
635
     */
636
    public function help_tabs_config()
637
    {
638
        return array();
639
    }
640
641
642
    /**
643
     * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into
644
     * the payment method's table's PMT_type column)
645
     * @return string
646
     */
647
    public function system_name()
648
    {
649
        $classname = get_class($this);
650
        return str_replace("EE_PMT_", '', $classname);
651
    }
652
653
654
    /**
655
     * A pretty i18n version of the PMT name
656
     * @return string
657
     */
658
    public function pretty_name()
659
    {
660
        return $this->_pretty_name;
661
    }
662
663
664
    /**
665
     * Gets the default absolute URL to the payment method type's button
666
     * @return string
667
     */
668
    public function default_button_url()
669
    {
670
        return $this->_default_button_url;
671
    }
672
673
674
    /**
675
     * Gets the gateway used by this payment method (if any)
676
     * @return EE_Gateway
677
     */
678
    public function get_gateway()
679
    {
680
        return $this->_gateway;
681
    }
682
683
684
    /**
685
     * @return string html for the link to a help tab
686
     */
687
    public function get_help_tab_link()
688
    {
689
        return EEH_Template::get_help_tab_link($this->get_help_tab_name());
690
    }
691
692
693
    /**
694
     * Returns the name of the help tab for this PMT
695
     * @return string
696
     */
697
    public function get_help_tab_name()
698
    {
699
        return 'ee_' . strtolower($this->system_name()) . '_help_tab';
700
    }
701
702
    /**
703
     * The name of the wp capability that should be associated with the usage of
704
     * this PMT by an admin
705
     * @return string
706
     */
707
    public function cap_name()
708
    {
709
        return 'ee_payment_method_' . strtolower($this->system_name());
710
    }
711
712
    /**
713
     * Called by client code to tell the gateway that if it wants to change
714
     * the transaction or line items or registrations related to teh payment it already
715
     * processed (we think, but possibly not) that now's the time to do it.
716
     * It is expected that gateways will store any info they need for this on the PAY_details,
717
     * or maybe an extra meta value
718
     * @param EE_Payment $payment
719
     * @return void
720
     */
721
    public function update_txn_based_on_payment($payment)
722
    {
723
        if ($this->_gateway instanceof EE_Gateway) {
724
            $this->_gateway->update_txn_based_on_payment($payment);
725
        }
726
    }
727
728
    /**
729
     * Returns a string of HTML describing this payment method type for an admin,
730
     * primarily intended for them to read before activating it.
731
     * The easiest way to set this is to create a folder 'templates' alongside
732
     * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php".
733
     * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php",
734
     * then you'd create a file named "templates" in the same folder as it, and name the file
735
     * "foo_bar_intro.template.php", and its content will be returned by this method
736
     * @return string
737
     */
738
    public function introductory_html()
739
    {
740
        return EEH_Template::locate_template($this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance));
741
    }
742
743
744
}
745