Completed
Branch BUG/446/fix-url-scheme-in-file... (316ea4)
by
unknown
61:53 queued 53:10
created
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.82.rc.014');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.82.rc.014');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_PMT_Base.lib.php 1 patch
Indentation   +808 added lines, -808 removed lines patch added patch discarded remove patch
@@ -21,812 +21,812 @@
 block discarded – undo
21 21
 abstract class EE_PMT_Base
22 22
 {
23 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
-     *
67
-     * @var string
68
-     */
69
-    protected $_file_folder = null;
70
-
71
-    /**
72
-     * String to the absolute URL to this file (useful for getting its web-accessible resources
73
-     * like images, js, or css)
74
-     *
75
-     * @var string
76
-     */
77
-    protected $_file_url = null;
78
-
79
-    /**
80
-     * Pretty name for the payment method
81
-     *
82
-     * @var string
83
-     */
84
-    protected $_pretty_name = null;
85
-
86
-    /**
87
-     *
88
-     * @var string
89
-     */
90
-    protected $_default_button_url = null;
91
-
92
-    /**
93
-     *
94
-     * @var string
95
-     */
96
-    protected $_default_description = null;
97
-
98
-
99
-    /**
100
-     *
101
-     * @param EE_Payment_Method $pm_instance
102
-     * @throws EE_Error
103
-     * @return EE_PMT_Base
104
-     */
105
-    public function __construct($pm_instance = null)
106
-    {
107
-        if ($pm_instance instanceof EE_Payment_Method) {
108
-            $this->set_instance($pm_instance);
109
-        }
110
-        if ($this->_gateway) {
111
-            $this->_gateway->set_payment_model(EEM_Payment::instance());
112
-            $this->_gateway->set_payment_log(EEM_Change_Log::instance());
113
-            $this->_gateway->set_template_helper(new EEH_Template());
114
-            $this->_gateway->set_line_item_helper(new EEH_Line_Item());
115
-            $this->_gateway->set_money_helper(new EEH_Money());
116
-            $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
117
-            $this->_gateway->set_unsupported_character_remover(new AsciiOnly());
118
-            do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
119
-        }
120
-        if (! isset($this->_has_billing_form)) {
121
-            // by default, On Site gateways have a billing form
122
-            if ($this->payment_occurs() == EE_PMT_Base::onsite) {
123
-                $this->set_has_billing_form(true);
124
-            } else {
125
-                $this->set_has_billing_form(false);
126
-            }
127
-        }
128
-
129
-        if (! $this->_pretty_name) {
130
-            throw new EE_Error(
131
-                sprintf(
132
-                    __(
133
-                        "You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized",
134
-                        "event_espresso"
135
-                    )
136
-                )
137
-            );
138
-        }
139
-        // if the child didn't specify a default button, use the credit card one
140
-        if ($this->_default_button_url === null) {
141
-            $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png';
142
-        }
143
-    }
144
-
145
-
146
-    /**
147
-     * @param boolean $has_billing_form
148
-     */
149
-    public function set_has_billing_form($has_billing_form)
150
-    {
151
-        $this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN);
152
-    }
153
-
154
-
155
-    /**
156
-     * sets the file_folder property
157
-     */
158
-    protected function _set_file_folder()
159
-    {
160
-        $reflector = new ReflectionClass(get_class($this));
161
-        $fn = $reflector->getFileName();
162
-        $this->_file_folder = dirname($fn) . DS;
163
-    }
164
-
165
-
166
-    /**
167
-     * sets the file URL with a trailing slash for this PMT
168
-     */
169
-    protected function _set_file_url()
170
-    {
171
-        $plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR);
172
-        $file_folder_fixed = str_replace('\\', DS, $this->file_folder());
173
-        $file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed);
174
-        $this->_file_url = set_url_scheme($file_path);
175
-    }
176
-
177
-    /**
178
-     * Gets the default description on all payment methods of this type
179
-     *
180
-     * @return string
181
-     */
182
-    public function default_description()
183
-    {
184
-        return $this->_default_description;
185
-    }
186
-
187
-
188
-    /**
189
-     * Returns the folder containing the PMT child class, with a trailing slash
190
-     *
191
-     * @return string
192
-     */
193
-    public function file_folder()
194
-    {
195
-        if (! $this->_file_folder) {
196
-            $this->_set_file_folder();
197
-        }
198
-        return $this->_file_folder;
199
-    }
200
-
201
-
202
-    /**
203
-     * @return string
204
-     */
205
-    public function file_url()
206
-    {
207
-        if (! $this->_file_url) {
208
-            $this->_set_file_url();
209
-        }
210
-        return $this->_file_url;
211
-    }
212
-
213
-
214
-    /**
215
-     * Sets the payment method instance this payment method type is for.
216
-     * Its important teh payment method instance is set before
217
-     *
218
-     * @param EE_Payment_Method $payment_method_instance
219
-     */
220
-    public function set_instance($payment_method_instance)
221
-    {
222
-        $this->_pm_instance = $payment_method_instance;
223
-        // if they have already requested the settings form, make sure its
224
-        // data matches this model object
225
-        if ($this->_settings_form) {
226
-            $this->settings_form()->populate_model_obj($payment_method_instance);
227
-        }
228
-        if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
229
-            $this->_gateway->set_settings($payment_method_instance->settings_array());
230
-        }
231
-    }
232
-
233
-
234
-    /**
235
-     * Gets teh form for displaying to admins where they setup the payment method
236
-     *
237
-     * @return EE_Payment_Method_Form
238
-     */
239
-    public function settings_form()
240
-    {
241
-        if (! $this->_settings_form) {
242
-            $this->_settings_form = $this->generate_new_settings_form();
243
-            $this->_settings_form->set_payment_method_type($this);
244
-            // if we have already assigned a model object to this pmt, make
245
-            // sure its reflected in teh form we just generated
246
-            if ($this->_pm_instance) {
247
-                $this->_settings_form->populate_model_obj($this->_pm_instance);
248
-            }
249
-        }
250
-        return $this->_settings_form;
251
-    }
252
-
253
-
254
-    /**
255
-     * Gets the form for all the settings related to this payment method type
256
-     *
257
-     * @return EE_Payment_Method_Form
258
-     */
259
-    abstract public function generate_new_settings_form();
260
-
261
-
262
-    /**
263
-     * Sets the form for settings. This may be useful if we have already received
264
-     * a form submission and have form data it in, and want to use it anytime we're showing
265
-     * this payment method type's settings form later in the request
266
-     *
267
-     * @param EE_Payment_Method_Form $form
268
-     */
269
-    public function set_settings_form($form)
270
-    {
271
-        $this->_settings_form = $form;
272
-    }
273
-
274
-
275
-    /**
276
-     * @return boolean
277
-     */
278
-    public function has_billing_form()
279
-    {
280
-        return $this->_has_billing_form;
281
-    }
282
-
283
-
284
-    /**
285
-     * Gets the form for displaying to attendees where they can enter their billing info
286
-     * which will be sent to teh gateway (can be null)
287
-     *
288
-     * @param \EE_Transaction $transaction
289
-     * @param array           $extra_args
290
-     * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null
291
-     */
292
-    public function billing_form(EE_Transaction $transaction = null, $extra_args = array())
293
-    {
294
-        // has billing form already been regenerated ? or overwrite cache?
295
-        if (! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) {
296
-            $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
297
-        }
298
-        // if we know who the attendee is, and this is a billing form
299
-        // that uses attendee info, populate it
300
-        if (apply_filters(
301
-            'FHEE__populate_billing_form_fields_from_attendee',
302
-            ($this->_billing_form instanceof EE_Billing_Attendee_Info_Form
303
-                && $transaction instanceof EE_Transaction
304
-                && $transaction->primary_registration() instanceof EE_Registration
305
-                && $transaction->primary_registration()->attendee() instanceof EE_Attendee
306
-            ),
307
-            $this->_billing_form,
308
-            $transaction
309
-        )) {
310
-            $this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee());
311
-        }
312
-        return $this->_billing_form;
313
-    }
314
-
315
-
316
-    /**
317
-     * Creates the billing form for this payment method type
318
-     *
319
-     * @param \EE_Transaction $transaction
320
-     * @return \EE_Billing_Info_Form
321
-     */
322
-    abstract public function generate_new_billing_form(EE_Transaction $transaction = null);
323
-
324
-
325
-    /**
326
-     * apply_billing_form_debug_settings
327
-     * applies debug data to the form
328
-     *
329
-     * @param \EE_Billing_Info_Form $billing_form
330
-     * @return \EE_Billing_Info_Form
331
-     */
332
-    public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form)
333
-    {
334
-        return $billing_form;
335
-    }
336
-
337
-
338
-    /**
339
-     * Sets the billing form for this payment method type. You may want to use this
340
-     * if you have form
341
-     *
342
-     * @param EE_Payment_Method $form
343
-     */
344
-    public function set_billing_form($form)
345
-    {
346
-        $this->_billing_form = $form;
347
-    }
348
-
349
-
350
-    /**
351
-     * Returns whether or not this payment method requires HTTPS to be used
352
-     *
353
-     * @return boolean
354
-     */
355
-    public function requires_https()
356
-    {
357
-        return $this->_requires_https;
358
-    }
359
-
360
-
361
-    /**
362
-     *
363
-     * @param EE_Transaction       $transaction
364
-     * @param float                $amount
365
-     * @param EE_Billing_Info_Form $billing_info
366
-     * @param string               $return_url
367
-     * @param string               $fail_url
368
-     * @param string               $method
369
-     * @param bool                 $by_admin
370
-     * @return EE_Payment
371
-     * @throws EE_Error
372
-     */
373
-    public function process_payment(
374
-        EE_Transaction $transaction,
375
-        $amount = null,
376
-        $billing_info = null,
377
-        $return_url = null,
378
-        $fail_url = '',
379
-        $method = 'CART',
380
-        $by_admin = false
381
-    ) {
382
-        // @todo: add surcharge for the payment method, if any
383
-        if ($this->_gateway) {
384
-            // there is a gateway, so we're going to make a payment object
385
-            // but wait! do they already have a payment in progress that we thought was failed?
386
-            $duplicate_properties = array(
387
-                'STS_ID'               => EEM_Payment::status_id_failed,
388
-                'TXN_ID'               => $transaction->ID(),
389
-                'PMD_ID'               => $this->_pm_instance->ID(),
390
-                'PAY_source'           => $method,
391
-                'PAY_amount'           => $amount !== null ? $amount : $transaction->remaining(),
392
-                'PAY_gateway_response' => null,
393
-            );
394
-            $payment = EEM_Payment::instance()->get_one(array($duplicate_properties));
395
-            // if we didn't already have a payment in progress for the same thing,
396
-            // then we actually want to make a new payment
397
-            if (! $payment instanceof EE_Payment) {
398
-                $payment = EE_Payment::new_instance(
399
-                    array_merge(
400
-                        $duplicate_properties,
401
-                        array(
402
-                            'PAY_timestamp'       => time(),
403
-                            'PAY_txn_id_chq_nmbr' => null,
404
-                            'PAY_po_number'       => null,
405
-                            'PAY_extra_accntng'   => null,
406
-                            'PAY_details'         => null,
407
-                        )
408
-                    )
409
-                );
410
-            }
411
-            // 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
412
-            $payment->save();
413
-            $billing_values = $this->_get_billing_values_from_form($billing_info);
414
-
415
-            //  Offsite Gateway
416
-            if ($this->_gateway instanceof EE_Offsite_Gateway) {
417
-                $payment = $this->_gateway->set_redirection_info(
418
-                    $payment,
419
-                    $billing_values,
420
-                    $return_url,
421
-                    EE_Config::instance()->core->txn_page_url(
422
-                        array(
423
-                            'e_reg_url_link'    => $transaction->primary_registration()->reg_url_link(),
424
-                            'ee_payment_method' => $this->_pm_instance->slug(),
425
-                        )
426
-                    ),
427
-                    $fail_url
428
-                );
429
-                $payment->save();
430
-                //  Onsite Gateway
431
-            } elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
432
-                $payment = $this->_gateway->do_direct_payment($payment, $billing_values);
433
-                $payment->save();
434
-            } else {
435
-                throw new EE_Error(
436
-                    sprintf(
437
-                        __(
438
-                            '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)',
439
-                            'event_espresso'
440
-                        ),
441
-                        get_class($this),
442
-                        gettype($this->_gateway)
443
-                    )
444
-                );
445
-            }
446
-        } else {
447
-            // no gateway provided
448
-            // there is no payment. Must be an offline gateway
449
-            // create a payment object anyways, but dont save it
450
-            $payment = EE_Payment::new_instance(
451
-                array(
452
-                    'STS_ID'        => EEM_Payment::status_id_pending,
453
-                    'TXN_ID'        => $transaction->ID(),
454
-                    'PMD_ID'        => $transaction->payment_method_ID(),
455
-                    'PAY_amount'    => 0.00,
456
-                    'PAY_timestamp' => time(),
457
-                )
458
-            );
459
-        }
460
-
461
-        // if there is billing info, clean it and save it now
462
-        if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
463
-            $this->_save_billing_info_to_attendee($billing_info, $transaction);
464
-        }
465
-
466
-        return $payment;
467
-    }
468
-
469
-    /**
470
-     * Gets the values we want to pass onto the gateway. Normally these
471
-     * are just the 'pretty' values, but there may be times the data may need
472
-     * a  little massaging. Proper subsections will become arrays of inputs
473
-     *
474
-     * @param EE_Billing_Info_Form $billing_form
475
-     * @return array
476
-     */
477
-    protected function _get_billing_values_from_form($billing_form)
478
-    {
479
-        if ($billing_form instanceof EE_Form_Section_Proper) {
480
-            return $billing_form->input_pretty_values(true);
481
-        } else {
482
-            return null;
483
-        }
484
-    }
485
-
486
-
487
-    /**
488
-     * Handles an instant payment notification when the transaction is known (by default).
489
-     *
490
-     * @param array          $req_data
491
-     * @param EE_Transaction $transaction
492
-     * @return EE_Payment
493
-     * @throws EE_Error
494
-     */
495
-    public function handle_ipn($req_data, $transaction)
496
-    {
497
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
498
-        if (! $this->_gateway instanceof EE_Offsite_Gateway) {
499
-            throw new EE_Error(
500
-                sprintf(
501
-                    __("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"),
502
-                    print_r($this->_gateway, true)
503
-                )
504
-            );
505
-        }
506
-        $payment = $this->_gateway->handle_payment_update($req_data, $transaction);
507
-        return $payment;
508
-    }
509
-
510
-
511
-    /**
512
-     * Saves the billing info onto the attendee of the primary registrant on this transaction, and
513
-     * cleans it first.
514
-     *
515
-     * @param EE_Billing_Attendee_Info_Form $billing_form
516
-     * @param EE_Transaction                $transaction
517
-     * @return boolean success
518
-     */
519
-    protected function _save_billing_info_to_attendee($billing_form, $transaction)
520
-    {
521
-        if (! $transaction || ! $transaction instanceof EE_Transaction) {
522
-            EE_Error::add_error(
523
-                __("Cannot save billing info because no transaction was specified", "event_espresso"),
524
-                __FILE__,
525
-                __FUNCTION__,
526
-                __LINE__
527
-            );
528
-            return false;
529
-        }
530
-        $primary_reg = $transaction->primary_registration();
531
-        if (! $primary_reg) {
532
-            EE_Error::add_error(
533
-                __("Cannot save billing info because the transaction has no primary registration", "event_espresso"),
534
-                __FILE__,
535
-                __FUNCTION__,
536
-                __LINE__
537
-            );
538
-            return false;
539
-        }
540
-        $attendee = $primary_reg->attendee();
541
-        if (! $attendee) {
542
-            EE_Error::add_error(
543
-                __(
544
-                    "Cannot save billing info because the transaction's primary registration has no attendee!",
545
-                    "event_espresso"
546
-                ),
547
-                __FILE__,
548
-                __FUNCTION__,
549
-                __LINE__
550
-            );
551
-            return false;
552
-        }
553
-        return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
554
-    }
555
-
556
-
557
-    /**
558
-     * Gets the payment this IPN is for. Children may often want to
559
-     * override this to inspect the request
560
-     *
561
-     * @param EE_Transaction $transaction
562
-     * @param array          $req_data
563
-     * @return EE_Payment
564
-     */
565
-    protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array())
566
-    {
567
-        return $transaction->last_payment();
568
-    }
569
-
570
-
571
-    /**
572
-     * In case generic code cannot provide the payment processor with a specific payment method
573
-     * and transaction, it will try calling this method on each activate payment method.
574
-     * If the payment method is able to identify the request as being for it, it should fetch
575
-     * the payment its for and return it. If not, it should throw an EE_Error to indicate it cannot
576
-     * handle the IPN
577
-     *
578
-     * @param array $req_data
579
-     * @return EE_Payment only if this payment method can find the info its needs from $req_data
580
-     * and identifies the IPN as being for this payment method (not just fo ra payment method of this type)
581
-     * @throws EE_Error
582
-     */
583
-    public function handle_unclaimed_ipn($req_data = array())
584
-    {
585
-        throw new EE_Error(
586
-            sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this))
587
-        );
588
-    }
589
-
590
-
591
-    /**
592
-     * Logic to be accomplished when the payment attempt is complete.
593
-     * Most payment methods don't need to do anything at this point; but some, like Mijireh, do.
594
-     * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from
595
-     * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status
596
-     * of the payment). Fed a transaction because it's always assumed to be the last payment that
597
-     * we're dealing with. Returns that last payment (if there is one)
598
-     *
599
-     * @param EE_Transaction $transaction
600
-     * @return EE_Payment
601
-     */
602
-    public function finalize_payment_for($transaction)
603
-    {
604
-        return $transaction->last_payment();
605
-    }
606
-
607
-
608
-    /**
609
-     * Whether or not this payment method's gateway supports sending refund requests
610
-     *
611
-     * @return boolean
612
-     */
613
-    public function supports_sending_refunds()
614
-    {
615
-        if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
616
-            return $this->_gateway->supports_sending_refunds();
617
-        } else {
618
-            return false;
619
-        }
620
-    }
621
-
622
-
623
-    /**
624
-     *
625
-     * @param EE_Payment $payment
626
-     * @param array      $refund_info
627
-     * @throws EE_Error
628
-     * @return EE_Payment
629
-     */
630
-    public function process_refund(EE_Payment $payment, $refund_info = array())
631
-    {
632
-        if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
633
-            return $this->_gateway->do_direct_refund($payment, $refund_info);
634
-        } else {
635
-            throw new EE_Error(
636
-                sprintf(
637
-                    __('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'),
638
-                    get_class($this)
639
-                )
640
-            );
641
-        }
642
-    }
643
-
644
-
645
-    /**
646
-     * Returns one the class's constants onsite,offsite, or offline, depending on this
647
-     * payment method's gateway.
648
-     *
649
-     * @return string
650
-     * @throws EE_Error
651
-     */
652
-    public function payment_occurs()
653
-    {
654
-        if (! $this->_gateway) {
655
-            return EE_PMT_Base::offline;
656
-        } elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
657
-            return EE_PMT_Base::onsite;
658
-        } elseif ($this->_gateway instanceof EE_Offsite_Gateway) {
659
-            return EE_PMT_Base::offsite;
660
-        } else {
661
-            throw new EE_Error(
662
-                sprintf(
663
-                    __(
664
-                        "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",
665
-                        "event_espresso"
666
-                    ),
667
-                    get_class($this)
668
-                )
669
-            );
670
-        }
671
-    }
672
-
673
-
674
-    /**
675
-     * For adding any html output ab ove the payment overview.
676
-     * Many gateways won't want ot display anything, so this function just returns an empty string.
677
-     * Other gateways may want to override this, such as offline gateways.
678
-     *
679
-     * @param EE_Payment $payment
680
-     * @return string
681
-     */
682
-    public function payment_overview_content(EE_Payment $payment)
683
-    {
684
-        return EEH_Template::display_template(
685
-            EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php',
686
-            array('payment_method' => $this->_pm_instance, 'payment' => $payment),
687
-            true
688
-        );
689
-    }
690
-
691
-
692
-    /**
693
-     * @return array where keys are the help tab name,
694
-     * values are: array {
695
-     * @type string $title         i18n name for the help tab
696
-     * @type string $filename      name of the file located in ./help_tabs/ (ie, in a folder next to this file)
697
-     * @type array  $template_args any arguments you want passed to the template file while rendering.
698
-     *                Keys will be variable names and values with be their values.
699
-     */
700
-    public function help_tabs_config()
701
-    {
702
-        return array();
703
-    }
704
-
705
-
706
-    /**
707
-     * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into
708
-     * the payment method's table's PMT_type column)
709
-     *
710
-     * @return string
711
-     */
712
-    public function system_name()
713
-    {
714
-        $classname = get_class($this);
715
-        return str_replace("EE_PMT_", '', $classname);
716
-    }
717
-
718
-
719
-    /**
720
-     * A pretty i18n version of the PMT name. Often the same as the "pretty_name", but you can change it by overriding
721
-     * this method.
722
-     * @return string
723
-     */
724
-    public function defaultFrontendName()
725
-    {
726
-        return $this->pretty_name();
727
-    }
728
-
729
-
730
-    /**
731
-     * A pretty i18n version of the PMT name
732
-     *
733
-     * @return string
734
-     */
735
-    public function pretty_name()
736
-    {
737
-        return $this->_pretty_name;
738
-    }
739
-
740
-
741
-    /**
742
-     * Gets the default absolute URL to the payment method type's button
743
-     *
744
-     * @return string
745
-     */
746
-    public function default_button_url()
747
-    {
748
-        return $this->_default_button_url;
749
-    }
750
-
751
-
752
-    /**
753
-     * Gets the gateway used by this payment method (if any)
754
-     *
755
-     * @return EE_Gateway
756
-     */
757
-    public function get_gateway()
758
-    {
759
-        return $this->_gateway;
760
-    }
761
-
762
-
763
-    /**
764
-     * @return string html for the link to a help tab
765
-     */
766
-    public function get_help_tab_link()
767
-    {
768
-        return EEH_Template::get_help_tab_link(
769
-            $this->get_help_tab_name(),
770
-            'espresso_payment_settings',
771
-            'default'
772
-        );
773
-    }
774
-
775
-
776
-    /**
777
-     * Returns the name of the help tab for this PMT
778
-     *
779
-     * @return string
780
-     */
781
-    public function get_help_tab_name()
782
-    {
783
-        return 'ee_' . strtolower($this->system_name()) . '_help_tab';
784
-    }
785
-
786
-    /**
787
-     * The name of the wp capability that should be associated with the usage of
788
-     * this PMT by an admin
789
-     *
790
-     * @return string
791
-     */
792
-    public function cap_name()
793
-    {
794
-        return 'ee_payment_method_' . strtolower($this->system_name());
795
-    }
796
-
797
-    /**
798
-     * Called by client code to tell the gateway that if it wants to change
799
-     * the transaction or line items or registrations related to teh payment it already
800
-     * processed (we think, but possibly not) that now's the time to do it.
801
-     * It is expected that gateways will store any info they need for this on the PAY_details,
802
-     * or maybe an extra meta value
803
-     *
804
-     * @param EE_Payment $payment
805
-     * @return void
806
-     */
807
-    public function update_txn_based_on_payment($payment)
808
-    {
809
-        if ($this->_gateway instanceof EE_Gateway) {
810
-            $this->_gateway->update_txn_based_on_payment($payment);
811
-        }
812
-    }
813
-
814
-    /**
815
-     * Returns a string of HTML describing this payment method type for an admin,
816
-     * primarily intended for them to read before activating it.
817
-     * The easiest way to set this is to create a folder 'templates' alongside
818
-     * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php".
819
-     * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php",
820
-     * then you'd create a file named "templates" in the same folder as it, and name the file
821
-     * "foo_bar_intro.template.php", and its content will be returned by this method
822
-     *
823
-     * @return string
824
-     */
825
-    public function introductory_html()
826
-    {
827
-        return EEH_Template::locate_template(
828
-            $this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php',
829
-            array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance)
830
-        );
831
-    }
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
+	 *
67
+	 * @var string
68
+	 */
69
+	protected $_file_folder = null;
70
+
71
+	/**
72
+	 * String to the absolute URL to this file (useful for getting its web-accessible resources
73
+	 * like images, js, or css)
74
+	 *
75
+	 * @var string
76
+	 */
77
+	protected $_file_url = null;
78
+
79
+	/**
80
+	 * Pretty name for the payment method
81
+	 *
82
+	 * @var string
83
+	 */
84
+	protected $_pretty_name = null;
85
+
86
+	/**
87
+	 *
88
+	 * @var string
89
+	 */
90
+	protected $_default_button_url = null;
91
+
92
+	/**
93
+	 *
94
+	 * @var string
95
+	 */
96
+	protected $_default_description = null;
97
+
98
+
99
+	/**
100
+	 *
101
+	 * @param EE_Payment_Method $pm_instance
102
+	 * @throws EE_Error
103
+	 * @return EE_PMT_Base
104
+	 */
105
+	public function __construct($pm_instance = null)
106
+	{
107
+		if ($pm_instance instanceof EE_Payment_Method) {
108
+			$this->set_instance($pm_instance);
109
+		}
110
+		if ($this->_gateway) {
111
+			$this->_gateway->set_payment_model(EEM_Payment::instance());
112
+			$this->_gateway->set_payment_log(EEM_Change_Log::instance());
113
+			$this->_gateway->set_template_helper(new EEH_Template());
114
+			$this->_gateway->set_line_item_helper(new EEH_Line_Item());
115
+			$this->_gateway->set_money_helper(new EEH_Money());
116
+			$this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
117
+			$this->_gateway->set_unsupported_character_remover(new AsciiOnly());
118
+			do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
119
+		}
120
+		if (! isset($this->_has_billing_form)) {
121
+			// by default, On Site gateways have a billing form
122
+			if ($this->payment_occurs() == EE_PMT_Base::onsite) {
123
+				$this->set_has_billing_form(true);
124
+			} else {
125
+				$this->set_has_billing_form(false);
126
+			}
127
+		}
128
+
129
+		if (! $this->_pretty_name) {
130
+			throw new EE_Error(
131
+				sprintf(
132
+					__(
133
+						"You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized",
134
+						"event_espresso"
135
+					)
136
+				)
137
+			);
138
+		}
139
+		// if the child didn't specify a default button, use the credit card one
140
+		if ($this->_default_button_url === null) {
141
+			$this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png';
142
+		}
143
+	}
144
+
145
+
146
+	/**
147
+	 * @param boolean $has_billing_form
148
+	 */
149
+	public function set_has_billing_form($has_billing_form)
150
+	{
151
+		$this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN);
152
+	}
153
+
154
+
155
+	/**
156
+	 * sets the file_folder property
157
+	 */
158
+	protected function _set_file_folder()
159
+	{
160
+		$reflector = new ReflectionClass(get_class($this));
161
+		$fn = $reflector->getFileName();
162
+		$this->_file_folder = dirname($fn) . DS;
163
+	}
164
+
165
+
166
+	/**
167
+	 * sets the file URL with a trailing slash for this PMT
168
+	 */
169
+	protected function _set_file_url()
170
+	{
171
+		$plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR);
172
+		$file_folder_fixed = str_replace('\\', DS, $this->file_folder());
173
+		$file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed);
174
+		$this->_file_url = set_url_scheme($file_path);
175
+	}
176
+
177
+	/**
178
+	 * Gets the default description on all payment methods of this type
179
+	 *
180
+	 * @return string
181
+	 */
182
+	public function default_description()
183
+	{
184
+		return $this->_default_description;
185
+	}
186
+
187
+
188
+	/**
189
+	 * Returns the folder containing the PMT child class, with a trailing slash
190
+	 *
191
+	 * @return string
192
+	 */
193
+	public function file_folder()
194
+	{
195
+		if (! $this->_file_folder) {
196
+			$this->_set_file_folder();
197
+		}
198
+		return $this->_file_folder;
199
+	}
200
+
201
+
202
+	/**
203
+	 * @return string
204
+	 */
205
+	public function file_url()
206
+	{
207
+		if (! $this->_file_url) {
208
+			$this->_set_file_url();
209
+		}
210
+		return $this->_file_url;
211
+	}
212
+
213
+
214
+	/**
215
+	 * Sets the payment method instance this payment method type is for.
216
+	 * Its important teh payment method instance is set before
217
+	 *
218
+	 * @param EE_Payment_Method $payment_method_instance
219
+	 */
220
+	public function set_instance($payment_method_instance)
221
+	{
222
+		$this->_pm_instance = $payment_method_instance;
223
+		// if they have already requested the settings form, make sure its
224
+		// data matches this model object
225
+		if ($this->_settings_form) {
226
+			$this->settings_form()->populate_model_obj($payment_method_instance);
227
+		}
228
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
229
+			$this->_gateway->set_settings($payment_method_instance->settings_array());
230
+		}
231
+	}
232
+
233
+
234
+	/**
235
+	 * Gets teh form for displaying to admins where they setup the payment method
236
+	 *
237
+	 * @return EE_Payment_Method_Form
238
+	 */
239
+	public function settings_form()
240
+	{
241
+		if (! $this->_settings_form) {
242
+			$this->_settings_form = $this->generate_new_settings_form();
243
+			$this->_settings_form->set_payment_method_type($this);
244
+			// if we have already assigned a model object to this pmt, make
245
+			// sure its reflected in teh form we just generated
246
+			if ($this->_pm_instance) {
247
+				$this->_settings_form->populate_model_obj($this->_pm_instance);
248
+			}
249
+		}
250
+		return $this->_settings_form;
251
+	}
252
+
253
+
254
+	/**
255
+	 * Gets the form for all the settings related to this payment method type
256
+	 *
257
+	 * @return EE_Payment_Method_Form
258
+	 */
259
+	abstract public function generate_new_settings_form();
260
+
261
+
262
+	/**
263
+	 * Sets the form for settings. This may be useful if we have already received
264
+	 * a form submission and have form data it in, and want to use it anytime we're showing
265
+	 * this payment method type's settings form later in the request
266
+	 *
267
+	 * @param EE_Payment_Method_Form $form
268
+	 */
269
+	public function set_settings_form($form)
270
+	{
271
+		$this->_settings_form = $form;
272
+	}
273
+
274
+
275
+	/**
276
+	 * @return boolean
277
+	 */
278
+	public function has_billing_form()
279
+	{
280
+		return $this->_has_billing_form;
281
+	}
282
+
283
+
284
+	/**
285
+	 * Gets the form for displaying to attendees where they can enter their billing info
286
+	 * which will be sent to teh gateway (can be null)
287
+	 *
288
+	 * @param \EE_Transaction $transaction
289
+	 * @param array           $extra_args
290
+	 * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null
291
+	 */
292
+	public function billing_form(EE_Transaction $transaction = null, $extra_args = array())
293
+	{
294
+		// has billing form already been regenerated ? or overwrite cache?
295
+		if (! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) {
296
+			$this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
297
+		}
298
+		// if we know who the attendee is, and this is a billing form
299
+		// that uses attendee info, populate it
300
+		if (apply_filters(
301
+			'FHEE__populate_billing_form_fields_from_attendee',
302
+			($this->_billing_form instanceof EE_Billing_Attendee_Info_Form
303
+				&& $transaction instanceof EE_Transaction
304
+				&& $transaction->primary_registration() instanceof EE_Registration
305
+				&& $transaction->primary_registration()->attendee() instanceof EE_Attendee
306
+			),
307
+			$this->_billing_form,
308
+			$transaction
309
+		)) {
310
+			$this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee());
311
+		}
312
+		return $this->_billing_form;
313
+	}
314
+
315
+
316
+	/**
317
+	 * Creates the billing form for this payment method type
318
+	 *
319
+	 * @param \EE_Transaction $transaction
320
+	 * @return \EE_Billing_Info_Form
321
+	 */
322
+	abstract public function generate_new_billing_form(EE_Transaction $transaction = null);
323
+
324
+
325
+	/**
326
+	 * apply_billing_form_debug_settings
327
+	 * applies debug data to the form
328
+	 *
329
+	 * @param \EE_Billing_Info_Form $billing_form
330
+	 * @return \EE_Billing_Info_Form
331
+	 */
332
+	public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form)
333
+	{
334
+		return $billing_form;
335
+	}
336
+
337
+
338
+	/**
339
+	 * Sets the billing form for this payment method type. You may want to use this
340
+	 * if you have form
341
+	 *
342
+	 * @param EE_Payment_Method $form
343
+	 */
344
+	public function set_billing_form($form)
345
+	{
346
+		$this->_billing_form = $form;
347
+	}
348
+
349
+
350
+	/**
351
+	 * Returns whether or not this payment method requires HTTPS to be used
352
+	 *
353
+	 * @return boolean
354
+	 */
355
+	public function requires_https()
356
+	{
357
+		return $this->_requires_https;
358
+	}
359
+
360
+
361
+	/**
362
+	 *
363
+	 * @param EE_Transaction       $transaction
364
+	 * @param float                $amount
365
+	 * @param EE_Billing_Info_Form $billing_info
366
+	 * @param string               $return_url
367
+	 * @param string               $fail_url
368
+	 * @param string               $method
369
+	 * @param bool                 $by_admin
370
+	 * @return EE_Payment
371
+	 * @throws EE_Error
372
+	 */
373
+	public function process_payment(
374
+		EE_Transaction $transaction,
375
+		$amount = null,
376
+		$billing_info = null,
377
+		$return_url = null,
378
+		$fail_url = '',
379
+		$method = 'CART',
380
+		$by_admin = false
381
+	) {
382
+		// @todo: add surcharge for the payment method, if any
383
+		if ($this->_gateway) {
384
+			// there is a gateway, so we're going to make a payment object
385
+			// but wait! do they already have a payment in progress that we thought was failed?
386
+			$duplicate_properties = array(
387
+				'STS_ID'               => EEM_Payment::status_id_failed,
388
+				'TXN_ID'               => $transaction->ID(),
389
+				'PMD_ID'               => $this->_pm_instance->ID(),
390
+				'PAY_source'           => $method,
391
+				'PAY_amount'           => $amount !== null ? $amount : $transaction->remaining(),
392
+				'PAY_gateway_response' => null,
393
+			);
394
+			$payment = EEM_Payment::instance()->get_one(array($duplicate_properties));
395
+			// if we didn't already have a payment in progress for the same thing,
396
+			// then we actually want to make a new payment
397
+			if (! $payment instanceof EE_Payment) {
398
+				$payment = EE_Payment::new_instance(
399
+					array_merge(
400
+						$duplicate_properties,
401
+						array(
402
+							'PAY_timestamp'       => time(),
403
+							'PAY_txn_id_chq_nmbr' => null,
404
+							'PAY_po_number'       => null,
405
+							'PAY_extra_accntng'   => null,
406
+							'PAY_details'         => null,
407
+						)
408
+					)
409
+				);
410
+			}
411
+			// 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
412
+			$payment->save();
413
+			$billing_values = $this->_get_billing_values_from_form($billing_info);
414
+
415
+			//  Offsite Gateway
416
+			if ($this->_gateway instanceof EE_Offsite_Gateway) {
417
+				$payment = $this->_gateway->set_redirection_info(
418
+					$payment,
419
+					$billing_values,
420
+					$return_url,
421
+					EE_Config::instance()->core->txn_page_url(
422
+						array(
423
+							'e_reg_url_link'    => $transaction->primary_registration()->reg_url_link(),
424
+							'ee_payment_method' => $this->_pm_instance->slug(),
425
+						)
426
+					),
427
+					$fail_url
428
+				);
429
+				$payment->save();
430
+				//  Onsite Gateway
431
+			} elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
432
+				$payment = $this->_gateway->do_direct_payment($payment, $billing_values);
433
+				$payment->save();
434
+			} else {
435
+				throw new EE_Error(
436
+					sprintf(
437
+						__(
438
+							'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)',
439
+							'event_espresso'
440
+						),
441
+						get_class($this),
442
+						gettype($this->_gateway)
443
+					)
444
+				);
445
+			}
446
+		} else {
447
+			// no gateway provided
448
+			// there is no payment. Must be an offline gateway
449
+			// create a payment object anyways, but dont save it
450
+			$payment = EE_Payment::new_instance(
451
+				array(
452
+					'STS_ID'        => EEM_Payment::status_id_pending,
453
+					'TXN_ID'        => $transaction->ID(),
454
+					'PMD_ID'        => $transaction->payment_method_ID(),
455
+					'PAY_amount'    => 0.00,
456
+					'PAY_timestamp' => time(),
457
+				)
458
+			);
459
+		}
460
+
461
+		// if there is billing info, clean it and save it now
462
+		if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
463
+			$this->_save_billing_info_to_attendee($billing_info, $transaction);
464
+		}
465
+
466
+		return $payment;
467
+	}
468
+
469
+	/**
470
+	 * Gets the values we want to pass onto the gateway. Normally these
471
+	 * are just the 'pretty' values, but there may be times the data may need
472
+	 * a  little massaging. Proper subsections will become arrays of inputs
473
+	 *
474
+	 * @param EE_Billing_Info_Form $billing_form
475
+	 * @return array
476
+	 */
477
+	protected function _get_billing_values_from_form($billing_form)
478
+	{
479
+		if ($billing_form instanceof EE_Form_Section_Proper) {
480
+			return $billing_form->input_pretty_values(true);
481
+		} else {
482
+			return null;
483
+		}
484
+	}
485
+
486
+
487
+	/**
488
+	 * Handles an instant payment notification when the transaction is known (by default).
489
+	 *
490
+	 * @param array          $req_data
491
+	 * @param EE_Transaction $transaction
492
+	 * @return EE_Payment
493
+	 * @throws EE_Error
494
+	 */
495
+	public function handle_ipn($req_data, $transaction)
496
+	{
497
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
498
+		if (! $this->_gateway instanceof EE_Offsite_Gateway) {
499
+			throw new EE_Error(
500
+				sprintf(
501
+					__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"),
502
+					print_r($this->_gateway, true)
503
+				)
504
+			);
505
+		}
506
+		$payment = $this->_gateway->handle_payment_update($req_data, $transaction);
507
+		return $payment;
508
+	}
509
+
510
+
511
+	/**
512
+	 * Saves the billing info onto the attendee of the primary registrant on this transaction, and
513
+	 * cleans it first.
514
+	 *
515
+	 * @param EE_Billing_Attendee_Info_Form $billing_form
516
+	 * @param EE_Transaction                $transaction
517
+	 * @return boolean success
518
+	 */
519
+	protected function _save_billing_info_to_attendee($billing_form, $transaction)
520
+	{
521
+		if (! $transaction || ! $transaction instanceof EE_Transaction) {
522
+			EE_Error::add_error(
523
+				__("Cannot save billing info because no transaction was specified", "event_espresso"),
524
+				__FILE__,
525
+				__FUNCTION__,
526
+				__LINE__
527
+			);
528
+			return false;
529
+		}
530
+		$primary_reg = $transaction->primary_registration();
531
+		if (! $primary_reg) {
532
+			EE_Error::add_error(
533
+				__("Cannot save billing info because the transaction has no primary registration", "event_espresso"),
534
+				__FILE__,
535
+				__FUNCTION__,
536
+				__LINE__
537
+			);
538
+			return false;
539
+		}
540
+		$attendee = $primary_reg->attendee();
541
+		if (! $attendee) {
542
+			EE_Error::add_error(
543
+				__(
544
+					"Cannot save billing info because the transaction's primary registration has no attendee!",
545
+					"event_espresso"
546
+				),
547
+				__FILE__,
548
+				__FUNCTION__,
549
+				__LINE__
550
+			);
551
+			return false;
552
+		}
553
+		return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
554
+	}
555
+
556
+
557
+	/**
558
+	 * Gets the payment this IPN is for. Children may often want to
559
+	 * override this to inspect the request
560
+	 *
561
+	 * @param EE_Transaction $transaction
562
+	 * @param array          $req_data
563
+	 * @return EE_Payment
564
+	 */
565
+	protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array())
566
+	{
567
+		return $transaction->last_payment();
568
+	}
569
+
570
+
571
+	/**
572
+	 * In case generic code cannot provide the payment processor with a specific payment method
573
+	 * and transaction, it will try calling this method on each activate payment method.
574
+	 * If the payment method is able to identify the request as being for it, it should fetch
575
+	 * the payment its for and return it. If not, it should throw an EE_Error to indicate it cannot
576
+	 * handle the IPN
577
+	 *
578
+	 * @param array $req_data
579
+	 * @return EE_Payment only if this payment method can find the info its needs from $req_data
580
+	 * and identifies the IPN as being for this payment method (not just fo ra payment method of this type)
581
+	 * @throws EE_Error
582
+	 */
583
+	public function handle_unclaimed_ipn($req_data = array())
584
+	{
585
+		throw new EE_Error(
586
+			sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this))
587
+		);
588
+	}
589
+
590
+
591
+	/**
592
+	 * Logic to be accomplished when the payment attempt is complete.
593
+	 * Most payment methods don't need to do anything at this point; but some, like Mijireh, do.
594
+	 * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from
595
+	 * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status
596
+	 * of the payment). Fed a transaction because it's always assumed to be the last payment that
597
+	 * we're dealing with. Returns that last payment (if there is one)
598
+	 *
599
+	 * @param EE_Transaction $transaction
600
+	 * @return EE_Payment
601
+	 */
602
+	public function finalize_payment_for($transaction)
603
+	{
604
+		return $transaction->last_payment();
605
+	}
606
+
607
+
608
+	/**
609
+	 * Whether or not this payment method's gateway supports sending refund requests
610
+	 *
611
+	 * @return boolean
612
+	 */
613
+	public function supports_sending_refunds()
614
+	{
615
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
616
+			return $this->_gateway->supports_sending_refunds();
617
+		} else {
618
+			return false;
619
+		}
620
+	}
621
+
622
+
623
+	/**
624
+	 *
625
+	 * @param EE_Payment $payment
626
+	 * @param array      $refund_info
627
+	 * @throws EE_Error
628
+	 * @return EE_Payment
629
+	 */
630
+	public function process_refund(EE_Payment $payment, $refund_info = array())
631
+	{
632
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
633
+			return $this->_gateway->do_direct_refund($payment, $refund_info);
634
+		} else {
635
+			throw new EE_Error(
636
+				sprintf(
637
+					__('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'),
638
+					get_class($this)
639
+				)
640
+			);
641
+		}
642
+	}
643
+
644
+
645
+	/**
646
+	 * Returns one the class's constants onsite,offsite, or offline, depending on this
647
+	 * payment method's gateway.
648
+	 *
649
+	 * @return string
650
+	 * @throws EE_Error
651
+	 */
652
+	public function payment_occurs()
653
+	{
654
+		if (! $this->_gateway) {
655
+			return EE_PMT_Base::offline;
656
+		} elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
657
+			return EE_PMT_Base::onsite;
658
+		} elseif ($this->_gateway instanceof EE_Offsite_Gateway) {
659
+			return EE_PMT_Base::offsite;
660
+		} else {
661
+			throw new EE_Error(
662
+				sprintf(
663
+					__(
664
+						"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",
665
+						"event_espresso"
666
+					),
667
+					get_class($this)
668
+				)
669
+			);
670
+		}
671
+	}
672
+
673
+
674
+	/**
675
+	 * For adding any html output ab ove the payment overview.
676
+	 * Many gateways won't want ot display anything, so this function just returns an empty string.
677
+	 * Other gateways may want to override this, such as offline gateways.
678
+	 *
679
+	 * @param EE_Payment $payment
680
+	 * @return string
681
+	 */
682
+	public function payment_overview_content(EE_Payment $payment)
683
+	{
684
+		return EEH_Template::display_template(
685
+			EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php',
686
+			array('payment_method' => $this->_pm_instance, 'payment' => $payment),
687
+			true
688
+		);
689
+	}
690
+
691
+
692
+	/**
693
+	 * @return array where keys are the help tab name,
694
+	 * values are: array {
695
+	 * @type string $title         i18n name for the help tab
696
+	 * @type string $filename      name of the file located in ./help_tabs/ (ie, in a folder next to this file)
697
+	 * @type array  $template_args any arguments you want passed to the template file while rendering.
698
+	 *                Keys will be variable names and values with be their values.
699
+	 */
700
+	public function help_tabs_config()
701
+	{
702
+		return array();
703
+	}
704
+
705
+
706
+	/**
707
+	 * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into
708
+	 * the payment method's table's PMT_type column)
709
+	 *
710
+	 * @return string
711
+	 */
712
+	public function system_name()
713
+	{
714
+		$classname = get_class($this);
715
+		return str_replace("EE_PMT_", '', $classname);
716
+	}
717
+
718
+
719
+	/**
720
+	 * A pretty i18n version of the PMT name. Often the same as the "pretty_name", but you can change it by overriding
721
+	 * this method.
722
+	 * @return string
723
+	 */
724
+	public function defaultFrontendName()
725
+	{
726
+		return $this->pretty_name();
727
+	}
728
+
729
+
730
+	/**
731
+	 * A pretty i18n version of the PMT name
732
+	 *
733
+	 * @return string
734
+	 */
735
+	public function pretty_name()
736
+	{
737
+		return $this->_pretty_name;
738
+	}
739
+
740
+
741
+	/**
742
+	 * Gets the default absolute URL to the payment method type's button
743
+	 *
744
+	 * @return string
745
+	 */
746
+	public function default_button_url()
747
+	{
748
+		return $this->_default_button_url;
749
+	}
750
+
751
+
752
+	/**
753
+	 * Gets the gateway used by this payment method (if any)
754
+	 *
755
+	 * @return EE_Gateway
756
+	 */
757
+	public function get_gateway()
758
+	{
759
+		return $this->_gateway;
760
+	}
761
+
762
+
763
+	/**
764
+	 * @return string html for the link to a help tab
765
+	 */
766
+	public function get_help_tab_link()
767
+	{
768
+		return EEH_Template::get_help_tab_link(
769
+			$this->get_help_tab_name(),
770
+			'espresso_payment_settings',
771
+			'default'
772
+		);
773
+	}
774
+
775
+
776
+	/**
777
+	 * Returns the name of the help tab for this PMT
778
+	 *
779
+	 * @return string
780
+	 */
781
+	public function get_help_tab_name()
782
+	{
783
+		return 'ee_' . strtolower($this->system_name()) . '_help_tab';
784
+	}
785
+
786
+	/**
787
+	 * The name of the wp capability that should be associated with the usage of
788
+	 * this PMT by an admin
789
+	 *
790
+	 * @return string
791
+	 */
792
+	public function cap_name()
793
+	{
794
+		return 'ee_payment_method_' . strtolower($this->system_name());
795
+	}
796
+
797
+	/**
798
+	 * Called by client code to tell the gateway that if it wants to change
799
+	 * the transaction or line items or registrations related to teh payment it already
800
+	 * processed (we think, but possibly not) that now's the time to do it.
801
+	 * It is expected that gateways will store any info they need for this on the PAY_details,
802
+	 * or maybe an extra meta value
803
+	 *
804
+	 * @param EE_Payment $payment
805
+	 * @return void
806
+	 */
807
+	public function update_txn_based_on_payment($payment)
808
+	{
809
+		if ($this->_gateway instanceof EE_Gateway) {
810
+			$this->_gateway->update_txn_based_on_payment($payment);
811
+		}
812
+	}
813
+
814
+	/**
815
+	 * Returns a string of HTML describing this payment method type for an admin,
816
+	 * primarily intended for them to read before activating it.
817
+	 * The easiest way to set this is to create a folder 'templates' alongside
818
+	 * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php".
819
+	 * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php",
820
+	 * then you'd create a file named "templates" in the same folder as it, and name the file
821
+	 * "foo_bar_intro.template.php", and its content will be returned by this method
822
+	 *
823
+	 * @return string
824
+	 */
825
+	public function introductory_html()
826
+	{
827
+		return EEH_Template::locate_template(
828
+			$this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php',
829
+			array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance)
830
+		);
831
+	}
832 832
 }
Please login to merge, or discard this patch.