Completed
Branch BUG-10202-persistent-admin-not... (8ac0a8)
by
unknown
101:22 queued 89:12
created
libraries/form_sections/inputs/EE_Form_Input_With_Options_Base.input.php 2 patches
Indentation   +319 added lines, -319 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -16,324 +16,324 @@  discard block
 block discarded – undo
16 16
 class EE_Form_Input_With_Options_Base extends EE_Form_Input_Base
17 17
 {
18 18
 
19
-    /**
20
-     * array of available options to choose as an answer
21
-     *
22
-     * @var array
23
-     */
24
-    protected $_options = array();
25
-
26
-    /**
27
-     * whether to display the html_label_text above the checkbox/radio button options
28
-     *
29
-     * @var boolean
30
-     */
31
-    protected $_display_html_label_text = true;
32
-
33
-    /**
34
-     * whether to display an question option description as part of the input label
35
-     *
36
-     * @var boolean
37
-     */
38
-    protected $_use_desc_in_label = true;
39
-
40
-    /**
41
-     * strlen() result for the longest input value (what gets displayed in the label)
42
-     * this is used to apply a css class to the input label
43
-     *
44
-     * @var int
45
-     */
46
-    protected $_label_size = 0;
47
-
48
-    /**
49
-     * whether to enforce the label size value passed in the constructor
50
-     *
51
-     * @var boolean
52
-     */
53
-    protected $_enforce_label_size = false;
54
-
55
-    /**
56
-     * whether to allow multiple selections (ie, the value of this input should be an array)
57
-     * or not (ie, the value should be a simple int, string, etc)
58
-     *
59
-     * @var boolean
60
-     */
61
-    protected $_multiple_selections = false;
62
-
63
-
64
-
65
-    /**
66
-     * @param array     $answer_options
67
-     * @param array     $input_settings {
68
-     * @type int|string $label_size
69
-     * @type boolean    $display_html_label_text
70
-     *                                  }
71
-     *                                  And all the options accepted by EE_Form_Input_Base
72
-     */
73
-    public function __construct($answer_options = array(), $input_settings = array())
74
-    {
75
-        if (isset($input_settings['label_size'])) {
76
-            $this->_set_label_size($input_settings['label_size']);
77
-            if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) {
78
-                $this->_enforce_label_size = true;
79
-            }
80
-        }
81
-        if (isset($input_settings['display_html_label_text'])) {
82
-            $this->set_display_html_label_text($input_settings['display_html_label_text']);
83
-        }
84
-        $this->set_select_options($answer_options);
85
-        parent::__construct($input_settings);
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * Sets the allowed options for this input. Also has the side-effect of
92
-     * updating the normalization strategy to match the keys provided in the array
93
-     *
94
-     * @param array $answer_options
95
-     * @return void  just has the side-effect of setting the options for this input
96
-     */
97
-    public function set_select_options($answer_options = array())
98
-    {
99
-        $answer_options = is_array($answer_options) ? $answer_options : array($answer_options);
100
-        //get the first item in the select options and check it's type
101
-        $this->_options = reset($answer_options) instanceof EE_Question_Option
102
-            ? $this->_process_question_options($answer_options)
103
-            : $answer_options;
104
-        //d( $this->_options );
105
-        $select_option_keys = array_keys($this->_options);
106
-        // attempt to determine data type for values in order to set normalization type
107
-        //purposefully only
108
-        if (
109
-            count($this->_options) === 2
110
-            && (
111
-                (in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true))
112
-                || (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true))
113
-            )
114
-        ) {
115
-            // values appear to be boolean, like TRUE, FALSE, 1, 0
116
-            $normalization = new EE_Boolean_Normalization();
117
-        } else {
118
-            //are ALL the options ints (even if we're using a multi-dimensional array)? If so use int validation
119
-            $all_ints = true;
120
-            array_walk_recursive(
121
-                $this->_options,
122
-                function($value,$key) use (&$all_ints){
123
-                    //is this a top-level key? ignore it
124
-                    if(! is_array($value)
125
-                        && ! is_int($key)
126
-                       && $key !== ''
127
-                       && $key !== null){
128
-                        $all_ints = false;
129
-                    }
130
-                }
131
-            );
132
-            if ($all_ints) {
133
-                $normalization = new EE_Int_Normalization();
134
-            } else {
135
-                $normalization = new EE_Text_Normalization();
136
-            }
137
-        }
138
-        // does input type have multiple options ?
139
-        if ($this->_multiple_selections) {
140
-            $this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization));
141
-        } else {
142
-            $this->_set_normalization_strategy($normalization);
143
-        }
144
-    }
145
-
146
-
147
-
148
-    /**
149
-     * @return array
150
-     */
151
-    public function options()
152
-    {
153
-        return $this->_options;
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     * Returns an array which is guaranteed to not be multidimensional
160
-     *
161
-     * @return array
162
-     */
163
-    public function flat_options()
164
-    {
165
-        return $this->_flatten_select_options($this->options());
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     * Makes sure $arr is a flat array, not a multidimensional one
172
-     *
173
-     * @param array $arr
174
-     * @return array
175
-     */
176
-    protected function _flatten_select_options($arr)
177
-    {
178
-        $flat_array = array();
179
-        if (EEH_Array::is_multi_dimensional_array($arr)) {
180
-            foreach ($arr as $sub_array) {
181
-                foreach ((array)$sub_array as $key => $value) {
182
-                    $flat_array[$key] = $value;
183
-                    $this->_set_label_size($value);
184
-                }
185
-            }
186
-        } else {
187
-            foreach ($arr as $key => $value) {
188
-                $flat_array[$key] = $value;
189
-                $this->_set_label_size($value);
190
-            }
191
-        }
192
-        return $flat_array;
193
-    }
194
-
195
-
196
-
197
-    /**
198
-     * @param EE_Question_Option[] $question_options_array
199
-     * @return array
200
-     */
201
-    protected function _process_question_options($question_options_array = array())
202
-    {
203
-        $flat_array = array();
204
-        foreach ($question_options_array as $question_option) {
205
-            if ($question_option instanceof EE_Question_Option) {
206
-                $desc = '';
207
-                if ($this->_use_desc_in_label) {
208
-                    $desc = $question_option->desc();
209
-                    $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : '';
210
-                }
211
-                $value = $question_option->value();
212
-                // add value even if it's empty
213
-                $flat_array[$value] = $value;
214
-                // if both value and desc are not empty, then separate with a dash
215
-                if ( ! empty($value) && ! empty($desc)) {
216
-                    $flat_array[$value] .= ' - ' . $desc;
217
-                } else {
218
-                    // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary
219
-                    $flat_array[$value] .= $desc;
220
-                }
221
-            } elseif (is_array($question_option)) {
222
-                $flat_array += $this->_flatten_select_options($question_option);
223
-            }
224
-        }
225
-        return $flat_array;
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     *    set_label_sizes
232
-     *
233
-     * @return void
234
-     */
235
-    public function set_label_sizes()
236
-    {
237
-        // did the input settings specifically say to NOT set the label size dynamically ?
238
-        if ( ! $this->_enforce_label_size) {
239
-            foreach ($this->_options as $option) {
240
-                // calculate the strlen of the label
241
-                $this->_set_label_size($option);
242
-            }
243
-        }
244
-    }
245
-
246
-
247
-
248
-    /**
249
-     *    _set_label_size_class
250
-     *
251
-     * @param int|string $value
252
-     * @return void
253
-     */
254
-    private function _set_label_size($value = '')
255
-    {
256
-        // don't change label size if it has already been set and is being enforced
257
-        if($this->_enforce_label_size && $this->_label_size >  0) {
258
-            return;
259
-        }
260
-        // determine length of option value
261
-        $val_size = is_int($value) ? $value : strlen($value);
262
-        // use new value if bigger than existing
263
-        $this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size;
264
-    }
265
-
266
-
267
-
268
-    /**
269
-     *    get_label_size_class
270
-     *
271
-     * @return string
272
-     */
273
-    public function get_label_size_class()
274
-    {
275
-        $size = ' medium-lbl';
276
-        // use maximum option value length to determine label size
277
-        if ($this->_label_size < 3) {
278
-            $size = ' nano-lbl';
279
-        } else if ($this->_label_size < 6) {
280
-            $size = ' micro-lbl';
281
-        } else if ($this->_label_size < 12) {
282
-            $size = ' tiny-lbl';
283
-        } else if ($this->_label_size < 25) {
284
-            $size = ' small-lbl';
285
-        } else if ($this->_label_size < 50) {
286
-            $size = ' medium-lbl';
287
-        } else if ($this->_label_size >= 100) {
288
-            $size = ' big-lbl';
289
-        }
290
-        return $size;
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     * Returns the pretty value for the normalized value
297
-     *
298
-     * @return string
299
-     */
300
-    public function pretty_value()
301
-    {
302
-        $options = $this->flat_options();
303
-        $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value);
304
-        if ( ! $this->_multiple_selections) {
305
-            $unnormalized_value_choices = array($unnormalized_value_choices);
306
-        }
307
-        $pretty_strings = array();
308
-        foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) {
309
-            if (isset($options[$unnormalized_value_choice])) {
310
-                $pretty_strings[] = $options[$unnormalized_value_choice];
311
-            } else {
312
-                $pretty_strings[] = $this->normalized_value();
313
-            }
314
-        }
315
-        return implode(', ', $pretty_strings);
316
-    }
317
-
318
-
319
-
320
-    /**
321
-     * @return boolean
322
-     */
323
-    public function display_html_label_text()
324
-    {
325
-        return $this->_display_html_label_text;
326
-    }
327
-
328
-
329
-
330
-    /**
331
-     * @param boolean $display_html_label_text
332
-     */
333
-    public function set_display_html_label_text($display_html_label_text)
334
-    {
335
-        $this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN);
336
-    }
19
+	/**
20
+	 * array of available options to choose as an answer
21
+	 *
22
+	 * @var array
23
+	 */
24
+	protected $_options = array();
25
+
26
+	/**
27
+	 * whether to display the html_label_text above the checkbox/radio button options
28
+	 *
29
+	 * @var boolean
30
+	 */
31
+	protected $_display_html_label_text = true;
32
+
33
+	/**
34
+	 * whether to display an question option description as part of the input label
35
+	 *
36
+	 * @var boolean
37
+	 */
38
+	protected $_use_desc_in_label = true;
39
+
40
+	/**
41
+	 * strlen() result for the longest input value (what gets displayed in the label)
42
+	 * this is used to apply a css class to the input label
43
+	 *
44
+	 * @var int
45
+	 */
46
+	protected $_label_size = 0;
47
+
48
+	/**
49
+	 * whether to enforce the label size value passed in the constructor
50
+	 *
51
+	 * @var boolean
52
+	 */
53
+	protected $_enforce_label_size = false;
54
+
55
+	/**
56
+	 * whether to allow multiple selections (ie, the value of this input should be an array)
57
+	 * or not (ie, the value should be a simple int, string, etc)
58
+	 *
59
+	 * @var boolean
60
+	 */
61
+	protected $_multiple_selections = false;
62
+
63
+
64
+
65
+	/**
66
+	 * @param array     $answer_options
67
+	 * @param array     $input_settings {
68
+	 * @type int|string $label_size
69
+	 * @type boolean    $display_html_label_text
70
+	 *                                  }
71
+	 *                                  And all the options accepted by EE_Form_Input_Base
72
+	 */
73
+	public function __construct($answer_options = array(), $input_settings = array())
74
+	{
75
+		if (isset($input_settings['label_size'])) {
76
+			$this->_set_label_size($input_settings['label_size']);
77
+			if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) {
78
+				$this->_enforce_label_size = true;
79
+			}
80
+		}
81
+		if (isset($input_settings['display_html_label_text'])) {
82
+			$this->set_display_html_label_text($input_settings['display_html_label_text']);
83
+		}
84
+		$this->set_select_options($answer_options);
85
+		parent::__construct($input_settings);
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * Sets the allowed options for this input. Also has the side-effect of
92
+	 * updating the normalization strategy to match the keys provided in the array
93
+	 *
94
+	 * @param array $answer_options
95
+	 * @return void  just has the side-effect of setting the options for this input
96
+	 */
97
+	public function set_select_options($answer_options = array())
98
+	{
99
+		$answer_options = is_array($answer_options) ? $answer_options : array($answer_options);
100
+		//get the first item in the select options and check it's type
101
+		$this->_options = reset($answer_options) instanceof EE_Question_Option
102
+			? $this->_process_question_options($answer_options)
103
+			: $answer_options;
104
+		//d( $this->_options );
105
+		$select_option_keys = array_keys($this->_options);
106
+		// attempt to determine data type for values in order to set normalization type
107
+		//purposefully only
108
+		if (
109
+			count($this->_options) === 2
110
+			&& (
111
+				(in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true))
112
+				|| (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true))
113
+			)
114
+		) {
115
+			// values appear to be boolean, like TRUE, FALSE, 1, 0
116
+			$normalization = new EE_Boolean_Normalization();
117
+		} else {
118
+			//are ALL the options ints (even if we're using a multi-dimensional array)? If so use int validation
119
+			$all_ints = true;
120
+			array_walk_recursive(
121
+				$this->_options,
122
+				function($value,$key) use (&$all_ints){
123
+					//is this a top-level key? ignore it
124
+					if(! is_array($value)
125
+						&& ! is_int($key)
126
+					   && $key !== ''
127
+					   && $key !== null){
128
+						$all_ints = false;
129
+					}
130
+				}
131
+			);
132
+			if ($all_ints) {
133
+				$normalization = new EE_Int_Normalization();
134
+			} else {
135
+				$normalization = new EE_Text_Normalization();
136
+			}
137
+		}
138
+		// does input type have multiple options ?
139
+		if ($this->_multiple_selections) {
140
+			$this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization));
141
+		} else {
142
+			$this->_set_normalization_strategy($normalization);
143
+		}
144
+	}
145
+
146
+
147
+
148
+	/**
149
+	 * @return array
150
+	 */
151
+	public function options()
152
+	{
153
+		return $this->_options;
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 * Returns an array which is guaranteed to not be multidimensional
160
+	 *
161
+	 * @return array
162
+	 */
163
+	public function flat_options()
164
+	{
165
+		return $this->_flatten_select_options($this->options());
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 * Makes sure $arr is a flat array, not a multidimensional one
172
+	 *
173
+	 * @param array $arr
174
+	 * @return array
175
+	 */
176
+	protected function _flatten_select_options($arr)
177
+	{
178
+		$flat_array = array();
179
+		if (EEH_Array::is_multi_dimensional_array($arr)) {
180
+			foreach ($arr as $sub_array) {
181
+				foreach ((array)$sub_array as $key => $value) {
182
+					$flat_array[$key] = $value;
183
+					$this->_set_label_size($value);
184
+				}
185
+			}
186
+		} else {
187
+			foreach ($arr as $key => $value) {
188
+				$flat_array[$key] = $value;
189
+				$this->_set_label_size($value);
190
+			}
191
+		}
192
+		return $flat_array;
193
+	}
194
+
195
+
196
+
197
+	/**
198
+	 * @param EE_Question_Option[] $question_options_array
199
+	 * @return array
200
+	 */
201
+	protected function _process_question_options($question_options_array = array())
202
+	{
203
+		$flat_array = array();
204
+		foreach ($question_options_array as $question_option) {
205
+			if ($question_option instanceof EE_Question_Option) {
206
+				$desc = '';
207
+				if ($this->_use_desc_in_label) {
208
+					$desc = $question_option->desc();
209
+					$desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : '';
210
+				}
211
+				$value = $question_option->value();
212
+				// add value even if it's empty
213
+				$flat_array[$value] = $value;
214
+				// if both value and desc are not empty, then separate with a dash
215
+				if ( ! empty($value) && ! empty($desc)) {
216
+					$flat_array[$value] .= ' - ' . $desc;
217
+				} else {
218
+					// otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary
219
+					$flat_array[$value] .= $desc;
220
+				}
221
+			} elseif (is_array($question_option)) {
222
+				$flat_array += $this->_flatten_select_options($question_option);
223
+			}
224
+		}
225
+		return $flat_array;
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 *    set_label_sizes
232
+	 *
233
+	 * @return void
234
+	 */
235
+	public function set_label_sizes()
236
+	{
237
+		// did the input settings specifically say to NOT set the label size dynamically ?
238
+		if ( ! $this->_enforce_label_size) {
239
+			foreach ($this->_options as $option) {
240
+				// calculate the strlen of the label
241
+				$this->_set_label_size($option);
242
+			}
243
+		}
244
+	}
245
+
246
+
247
+
248
+	/**
249
+	 *    _set_label_size_class
250
+	 *
251
+	 * @param int|string $value
252
+	 * @return void
253
+	 */
254
+	private function _set_label_size($value = '')
255
+	{
256
+		// don't change label size if it has already been set and is being enforced
257
+		if($this->_enforce_label_size && $this->_label_size >  0) {
258
+			return;
259
+		}
260
+		// determine length of option value
261
+		$val_size = is_int($value) ? $value : strlen($value);
262
+		// use new value if bigger than existing
263
+		$this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size;
264
+	}
265
+
266
+
267
+
268
+	/**
269
+	 *    get_label_size_class
270
+	 *
271
+	 * @return string
272
+	 */
273
+	public function get_label_size_class()
274
+	{
275
+		$size = ' medium-lbl';
276
+		// use maximum option value length to determine label size
277
+		if ($this->_label_size < 3) {
278
+			$size = ' nano-lbl';
279
+		} else if ($this->_label_size < 6) {
280
+			$size = ' micro-lbl';
281
+		} else if ($this->_label_size < 12) {
282
+			$size = ' tiny-lbl';
283
+		} else if ($this->_label_size < 25) {
284
+			$size = ' small-lbl';
285
+		} else if ($this->_label_size < 50) {
286
+			$size = ' medium-lbl';
287
+		} else if ($this->_label_size >= 100) {
288
+			$size = ' big-lbl';
289
+		}
290
+		return $size;
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 * Returns the pretty value for the normalized value
297
+	 *
298
+	 * @return string
299
+	 */
300
+	public function pretty_value()
301
+	{
302
+		$options = $this->flat_options();
303
+		$unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value);
304
+		if ( ! $this->_multiple_selections) {
305
+			$unnormalized_value_choices = array($unnormalized_value_choices);
306
+		}
307
+		$pretty_strings = array();
308
+		foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) {
309
+			if (isset($options[$unnormalized_value_choice])) {
310
+				$pretty_strings[] = $options[$unnormalized_value_choice];
311
+			} else {
312
+				$pretty_strings[] = $this->normalized_value();
313
+			}
314
+		}
315
+		return implode(', ', $pretty_strings);
316
+	}
317
+
318
+
319
+
320
+	/**
321
+	 * @return boolean
322
+	 */
323
+	public function display_html_label_text()
324
+	{
325
+		return $this->_display_html_label_text;
326
+	}
327
+
328
+
329
+
330
+	/**
331
+	 * @param boolean $display_html_label_text
332
+	 */
333
+	public function set_display_html_label_text($display_html_label_text)
334
+	{
335
+		$this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN);
336
+	}
337 337
 
338 338
 
339 339
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
             $all_ints = true;
120 120
             array_walk_recursive(
121 121
                 $this->_options,
122
-                function($value,$key) use (&$all_ints){
122
+                function($value, $key) use (&$all_ints){
123 123
                     //is this a top-level key? ignore it
124
-                    if(! is_array($value)
124
+                    if ( ! is_array($value)
125 125
                         && ! is_int($key)
126 126
                        && $key !== ''
127
-                       && $key !== null){
127
+                       && $key !== null) {
128 128
                         $all_ints = false;
129 129
                     }
130 130
                 }
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
         $flat_array = array();
179 179
         if (EEH_Array::is_multi_dimensional_array($arr)) {
180 180
             foreach ($arr as $sub_array) {
181
-                foreach ((array)$sub_array as $key => $value) {
181
+                foreach ((array) $sub_array as $key => $value) {
182 182
                     $flat_array[$key] = $value;
183 183
                     $this->_set_label_size($value);
184 184
                 }
@@ -206,14 +206,14 @@  discard block
 block discarded – undo
206 206
                 $desc = '';
207 207
                 if ($this->_use_desc_in_label) {
208 208
                     $desc = $question_option->desc();
209
-                    $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : '';
209
+                    $desc = ! empty($desc) ? '<span class="ee-question-option-desc">'.$desc.'</span>' : '';
210 210
                 }
211 211
                 $value = $question_option->value();
212 212
                 // add value even if it's empty
213 213
                 $flat_array[$value] = $value;
214 214
                 // if both value and desc are not empty, then separate with a dash
215 215
                 if ( ! empty($value) && ! empty($desc)) {
216
-                    $flat_array[$value] .= ' - ' . $desc;
216
+                    $flat_array[$value] .= ' - '.$desc;
217 217
                 } else {
218 218
                     // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary
219 219
                     $flat_array[$value] .= $desc;
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
     private function _set_label_size($value = '')
255 255
     {
256 256
         // don't change label size if it has already been set and is being enforced
257
-        if($this->_enforce_label_size && $this->_label_size >  0) {
257
+        if ($this->_enforce_label_size && $this->_label_size > 0) {
258 258
             return;
259 259
         }
260 260
         // determine length of option value
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
             $unnormalized_value_choices = array($unnormalized_value_choices);
306 306
         }
307 307
         $pretty_strings = array();
308
-        foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) {
308
+        foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) {
309 309
             if (isset($options[$unnormalized_value_choice])) {
310 310
                 $pretty_strings[] = $options[$unnormalized_value_choice];
311 311
             } else {
Please login to merge, or discard this patch.
payment_methods/Paypal_Express/EE_PMT_Paypal_Express.pm.php 2 patches
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('NO direct script access allowed');
2
+	exit('NO direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -17,153 +17,153 @@  discard block
 block discarded – undo
17 17
 class EE_PMT_Paypal_Express extends EE_PMT_Base
18 18
 {
19 19
 
20
-    /**
21
-     * EE_PMT_Paypal_Express constructor.
22
-     */
23
-    public function __construct($pm_instance = null)
24
-    {
25
-        require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php');
26
-        $this->_gateway = new EEG_Paypal_Express();
20
+	/**
21
+	 * EE_PMT_Paypal_Express constructor.
22
+	 */
23
+	public function __construct($pm_instance = null)
24
+	{
25
+		require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php');
26
+		$this->_gateway = new EEG_Paypal_Express();
27 27
 
28
-        $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso');
29
-        $this->_template_path = $this->file_folder() . 'templates' . DS;
30
-        $this->_default_description = esc_html__(
31
-            // @codingStandardsIgnoreStart
32
-            'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.',
33
-            // @codingStandardsIgnoreEnd
34
-            'event_espresso'
35
-        );
36
-        $this->_default_button_url = $this->file_url() . 'lib' . DS . 'paypal-express-checkout-logo.png';
28
+		$this->_pretty_name = esc_html__('PayPal Express', 'event_espresso');
29
+		$this->_template_path = $this->file_folder() . 'templates' . DS;
30
+		$this->_default_description = esc_html__(
31
+			// @codingStandardsIgnoreStart
32
+			'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.',
33
+			// @codingStandardsIgnoreEnd
34
+			'event_espresso'
35
+		);
36
+		$this->_default_button_url = $this->file_url() . 'lib' . DS . 'paypal-express-checkout-logo.png';
37 37
 
38
-        parent::__construct($pm_instance);
39
-    }
38
+		parent::__construct($pm_instance);
39
+	}
40 40
 
41 41
 
42
-    /**
43
-     * Adds the help tab.
44
-     *
45
-     * @see EE_PMT_Base::help_tabs_config()
46
-     * @return array
47
-     */
48
-    public function help_tabs_config()
49
-    {
50
-        return array(
51
-            $this->get_help_tab_name() => array(
52
-                'title'    => esc_html__('PayPal Express Settings', 'event_espresso'),
53
-                'filename' => 'payment_methods_overview_paypal_express'
54
-            )
55
-        );
56
-    }
42
+	/**
43
+	 * Adds the help tab.
44
+	 *
45
+	 * @see EE_PMT_Base::help_tabs_config()
46
+	 * @return array
47
+	 */
48
+	public function help_tabs_config()
49
+	{
50
+		return array(
51
+			$this->get_help_tab_name() => array(
52
+				'title'    => esc_html__('PayPal Express Settings', 'event_espresso'),
53
+				'filename' => 'payment_methods_overview_paypal_express'
54
+			)
55
+		);
56
+	}
57 57
 
58 58
 
59
-    /**
60
-     * Gets the form for all the settings related to this payment method type.
61
-     *
62
-     * @return EE_Payment_Method_Form
63
-     */
64
-    public function generate_new_settings_form()
65
-    {
66
-        EE_Registry::instance()->load_helper('Template');
67
-        $form = new EE_Payment_Method_Form(
68
-            array(
69
-                'extra_meta_inputs' => array(
70
-                    'api_username' => new EE_Text_Input(
71
-                        array(
72
-                            'html_label_text' => sprintf(
73
-                                esc_html__('API Username %s', 'event_espresso'),
74
-                                $this->get_help_tab_link()
75
-                            ),
76
-                            'required'        => true,
77
-                        )
78
-                    ),
79
-                    'api_password' => new EE_Text_Input(
80
-                        array(
81
-                            'html_label_text' => sprintf(
82
-                                esc_html__('API Password %s', 'event_espresso'),
83
-                                $this->get_help_tab_link()
84
-                            ),
85
-                            'required'        => true,
86
-                        )
87
-                    ),
88
-                    'api_signature' => new EE_Text_Input(
89
-                        array(
90
-                            'html_label_text' => sprintf(
91
-                                esc_html__('API Signature %s', 'event_espresso'),
92
-                                $this->get_help_tab_link()
93
-                            ),
94
-                            'required'        => true,
95
-                        )
96
-                    ),
97
-                    'request_shipping_addr' => new EE_Yes_No_Input(
98
-                        array(
99
-                            'html_label_text' => sprintf(
100
-                                esc_html__('Request Shipping Address %s', 'event_espresso'),
101
-                                $this->get_help_tab_link()
102
-                            ),
103
-                            'html_help_text'  => esc_html__(
104
-                                // @codingStandardsIgnoreStart
105
-                                'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.',
106
-                                // @codingStandardsIgnoreEnd
107
-                                'event_espresso'
108
-                            ),
109
-                            'required'        => true,
110
-                            'default'         => false,
111
-                        )
112
-                    ),
113
-                    'image_url' => new EE_Admin_File_Uploader_Input(
114
-                        array(
115
-                            'html_label_text' => sprintf(
116
-                                esc_html__('Image URL %s', 'event_espresso'),
117
-                                $this->get_help_tab_link()
118
-                            ),
119
-                            'html_help_text'  => esc_html__(
120
-                                'Used for your business/personal logo on the PayPal page',
121
-                                'event_espresso'
122
-                            ),
123
-                            'required'        => false,
124
-                        )
125
-                    ),
126
-                )
127
-            )
128
-        );
129
-        return $form;
130
-    }
59
+	/**
60
+	 * Gets the form for all the settings related to this payment method type.
61
+	 *
62
+	 * @return EE_Payment_Method_Form
63
+	 */
64
+	public function generate_new_settings_form()
65
+	{
66
+		EE_Registry::instance()->load_helper('Template');
67
+		$form = new EE_Payment_Method_Form(
68
+			array(
69
+				'extra_meta_inputs' => array(
70
+					'api_username' => new EE_Text_Input(
71
+						array(
72
+							'html_label_text' => sprintf(
73
+								esc_html__('API Username %s', 'event_espresso'),
74
+								$this->get_help_tab_link()
75
+							),
76
+							'required'        => true,
77
+						)
78
+					),
79
+					'api_password' => new EE_Text_Input(
80
+						array(
81
+							'html_label_text' => sprintf(
82
+								esc_html__('API Password %s', 'event_espresso'),
83
+								$this->get_help_tab_link()
84
+							),
85
+							'required'        => true,
86
+						)
87
+					),
88
+					'api_signature' => new EE_Text_Input(
89
+						array(
90
+							'html_label_text' => sprintf(
91
+								esc_html__('API Signature %s', 'event_espresso'),
92
+								$this->get_help_tab_link()
93
+							),
94
+							'required'        => true,
95
+						)
96
+					),
97
+					'request_shipping_addr' => new EE_Yes_No_Input(
98
+						array(
99
+							'html_label_text' => sprintf(
100
+								esc_html__('Request Shipping Address %s', 'event_espresso'),
101
+								$this->get_help_tab_link()
102
+							),
103
+							'html_help_text'  => esc_html__(
104
+								// @codingStandardsIgnoreStart
105
+								'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.',
106
+								// @codingStandardsIgnoreEnd
107
+								'event_espresso'
108
+							),
109
+							'required'        => true,
110
+							'default'         => false,
111
+						)
112
+					),
113
+					'image_url' => new EE_Admin_File_Uploader_Input(
114
+						array(
115
+							'html_label_text' => sprintf(
116
+								esc_html__('Image URL %s', 'event_espresso'),
117
+								$this->get_help_tab_link()
118
+							),
119
+							'html_help_text'  => esc_html__(
120
+								'Used for your business/personal logo on the PayPal page',
121
+								'event_espresso'
122
+							),
123
+							'required'        => false,
124
+						)
125
+					),
126
+				)
127
+			)
128
+		);
129
+		return $form;
130
+	}
131 131
 
132 132
 
133
-    /**
134
-     * Creates a billing form for this payment method type.
135
-     *
136
-     * @param \EE_Transaction $transaction
137
-     * @return \EE_Billing_Info_Form
138
-     */
139
-    public function generate_new_billing_form(EE_Transaction $transaction = null)
140
-    {
141
-        if ($this->_pm_instance->debug_mode()) {
142
-            $form = new EE_Billing_Info_Form(
143
-                $this->_pm_instance,
144
-                array(
145
-                    'name' => 'paypal_express_Info_Form',
146
-                    'subsections' => array(
147
-                        'paypal_express_debug_info' => new EE_Form_Section_Proper(
148
-                            array(
149
-                                'layout_strategy' => new EE_Template_Layout(
150
-                                    array(
151
-                                        'layout_template_file' => $this->_template_path
152
-                                                                    . 'paypal_express_debug_info.template.php',
153
-                                        'template_args'        => array(
154
-                                            'debug_mode' => $this->_pm_instance->debug_mode()
155
-                                        )
156
-                                    )
157
-                                )
158
-                            )
159
-                        )
160
-                    )
161
-                )
162
-            );
163
-            return $form;
164
-        }
133
+	/**
134
+	 * Creates a billing form for this payment method type.
135
+	 *
136
+	 * @param \EE_Transaction $transaction
137
+	 * @return \EE_Billing_Info_Form
138
+	 */
139
+	public function generate_new_billing_form(EE_Transaction $transaction = null)
140
+	{
141
+		if ($this->_pm_instance->debug_mode()) {
142
+			$form = new EE_Billing_Info_Form(
143
+				$this->_pm_instance,
144
+				array(
145
+					'name' => 'paypal_express_Info_Form',
146
+					'subsections' => array(
147
+						'paypal_express_debug_info' => new EE_Form_Section_Proper(
148
+							array(
149
+								'layout_strategy' => new EE_Template_Layout(
150
+									array(
151
+										'layout_template_file' => $this->_template_path
152
+																	. 'paypal_express_debug_info.template.php',
153
+										'template_args'        => array(
154
+											'debug_mode' => $this->_pm_instance->debug_mode()
155
+										)
156
+									)
157
+								)
158
+							)
159
+						)
160
+					)
161
+				)
162
+			);
163
+			return $form;
164
+		}
165 165
 
166
-        return false;
167
-    }
166
+		return false;
167
+	}
168 168
 }
169 169
 // End of file EE_PMT_Paypal_Express.pm.php
170 170
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('NO direct script access allowed');
3 3
 }
4 4
 
@@ -22,18 +22,18 @@  discard block
 block discarded – undo
22 22
      */
23 23
     public function __construct($pm_instance = null)
24 24
     {
25
-        require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php');
25
+        require_once($this->file_folder().'EEG_Paypal_Express.gateway.php');
26 26
         $this->_gateway = new EEG_Paypal_Express();
27 27
 
28 28
         $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso');
29
-        $this->_template_path = $this->file_folder() . 'templates' . DS;
29
+        $this->_template_path = $this->file_folder().'templates'.DS;
30 30
         $this->_default_description = esc_html__(
31 31
             // @codingStandardsIgnoreStart
32 32
             'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.',
33 33
             // @codingStandardsIgnoreEnd
34 34
             'event_espresso'
35 35
         );
36
-        $this->_default_button_url = $this->file_url() . 'lib' . DS . 'paypal-express-checkout-logo.png';
36
+        $this->_default_button_url = $this->file_url().'lib'.DS.'paypal-express-checkout-logo.png';
37 37
 
38 38
         parent::__construct($pm_instance);
39 39
     }
Please login to merge, or discard this patch.
payment_methods/Paypal_Express/EEG_Paypal_Express.gateway.php 2 patches
Indentation   +669 added lines, -669 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('NO direct script access allowed');
2
+	exit('NO direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -16,678 +16,678 @@  discard block
 block discarded – undo
16 16
  */
17 17
 //Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP
18 18
 if (! function_exists('mb_strcut')) {
19
-    /**
20
-     * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
21
-     * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
22
-     * @param $string
23
-     * @param $start
24
-     * @param $length
25
-     * @return bool|string
26
-     */
27
-    function mb_strcut($string, $start, $length = null)
28
-    {
29
-        return mb_substr($string, $start, $length);
30
-    }
19
+	/**
20
+	 * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
21
+	 * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
22
+	 * @param $string
23
+	 * @param $start
24
+	 * @param $length
25
+	 * @return bool|string
26
+	 */
27
+	function mb_strcut($string, $start, $length = null)
28
+	{
29
+		return mb_substr($string, $start, $length);
30
+	}
31 31
 }
32 32
 class EEG_Paypal_Express extends EE_Offsite_Gateway
33 33
 {
34 34
 
35
-    /**
36
-     * Merchant API Username.
37
-     *
38
-     * @var string
39
-     */
40
-    protected $_api_username;
41
-
42
-    /**
43
-     * Merchant API Password.
44
-     *
45
-     * @var string
46
-     */
47
-    protected $_api_password;
48
-
49
-    /**
50
-     * API Signature.
51
-     *
52
-     * @var string
53
-     */
54
-    protected $_api_signature;
55
-
56
-    /**
57
-     * Request Shipping address on PP checkout page.
58
-     *
59
-     * @var string
60
-     */
61
-    protected $_request_shipping_addr;
62
-
63
-    /**
64
-     * Business/personal logo.
65
-     *
66
-     * @var string
67
-     */
68
-    protected $_image_url;
69
-
70
-    /**
71
-     * gateway URL variable
72
-     *
73
-     * @var string
74
-     */
75
-    protected $_base_gateway_url = '';
76
-
77
-
78
-
79
-    /**
80
-     * EEG_Paypal_Express constructor.
81
-     */
82
-    public function __construct()
83
-    {
84
-        $this->_currencies_supported = array(
85
-            'USD',
86
-            'AUD',
87
-            'BRL',
88
-            'CAD',
89
-            'CZK',
90
-            'DKK',
91
-            'EUR',
92
-            'HKD',
93
-            'HUF',
94
-            'ILS',
95
-            'JPY',
96
-            'MYR',
97
-            'MXN',
98
-            'NOK',
99
-            'NZD',
100
-            'PHP',
101
-            'PLN',
102
-            'GBP',
103
-            'RUB',
104
-            'SGD',
105
-            'SEK',
106
-            'CHF',
107
-            'TWD',
108
-            'THB',
109
-            'TRY',
110
-        );
111
-        parent::__construct();
112
-    }
113
-
114
-
115
-
116
-    /**
117
-     * Sets the gateway URL variable based on whether debug mode is enabled or not.
118
-     *
119
-     * @param array $settings_array
120
-     */
121
-    public function set_settings($settings_array)
122
-    {
123
-        parent::set_settings($settings_array);
124
-        // Redirect URL.
125
-        $this->_base_gateway_url = $this->_debug_mode
126
-            ? 'https://api-3t.sandbox.paypal.com/nvp'
127
-            : 'https://api-3t.paypal.com/nvp';
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @param EEI_Payment $payment
134
-     * @param array       $billing_info
135
-     * @param string      $return_url
136
-     * @param string      $notify_url
137
-     * @param string      $cancel_url
138
-     * @return \EE_Payment|\EEI_Payment
139
-     * @throws \EE_Error
140
-     */
141
-    public function set_redirection_info(
142
-        $payment,
143
-        $billing_info = array(),
144
-        $return_url = null,
145
-        $notify_url = null,
146
-        $cancel_url = null
147
-    ) {
148
-        if (! $payment instanceof EEI_Payment) {
149
-            $payment->set_gateway_response(
150
-                esc_html__(
151
-                    'Error. No associated payment was found.',
152
-                    'event_espresso'
153
-                )
154
-            );
155
-            $payment->set_status($this->_pay_model->failed_status());
156
-            return $payment;
157
-        }
158
-        $transaction = $payment->transaction();
159
-        if (! $transaction instanceof EEI_Transaction) {
160
-            $payment->set_gateway_response(
161
-                esc_html__(
162
-                    'Could not process this payment because it has no associated transaction.',
163
-                    'event_espresso'
164
-                )
165
-            );
166
-            $payment->set_status($this->_pay_model->failed_status());
167
-            return $payment;
168
-        }
169
-        $order_description = mb_strcut($this->_format_order_description($payment), 0, 127);
170
-        $primary_registration = $transaction->primary_registration();
171
-        $primary_attendee = $primary_registration instanceof EE_Registration
172
-            ? $primary_registration->attendee()
173
-            : false;
174
-        $locale = explode('-', get_bloginfo('language'));
175
-        // Gather request parameters.
176
-        $token_request_dtls = array(
177
-            'METHOD'                         => 'SetExpressCheckout',
178
-            'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
179
-            'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
180
-            'PAYMENTREQUEST_0_DESC'          => $order_description,
181
-            'RETURNURL'                      => $return_url,
182
-            'CANCELURL'                      => $cancel_url,
183
-            'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
184
-            // Buyer does not need to create a PayPal account to check out.
185
-            // This is referred to as PayPal Account Optional.
186
-            'SOLUTIONTYPE'                   => 'Sole',
187
-            //EE will blow up if you change this
188
-            'BUTTONSOURCE'                   => 'EventEspresso_SP',
189
-            // Locale of the pages displayed by PayPal during Express Checkout.
190
-            'LOCALECODE'                     => $locale[1]
191
-        );
192
-        // Show itemized list.
193
-        $itemized_list = $this->itemize_list($payment, $transaction);
194
-        $token_request_dtls = array_merge($token_request_dtls, $itemized_list);
195
-        // Automatically filling out shipping and contact information.
196
-        if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) {
197
-            // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
198
-            $token_request_dtls['NOSHIPPING'] = '2';
199
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address();
200
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2();
201
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city();
202
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev();
203
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID();
204
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
205
-            $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
206
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
207
-        } elseif (! $this->_request_shipping_addr) {
208
-            // Do not request shipping details on the PP Checkout page.
209
-            $token_request_dtls['NOSHIPPING'] = '1';
210
-            $token_request_dtls['REQCONFIRMSHIPPING'] = '0';
211
-        }
212
-        // Used a business/personal logo on the PayPal page.
213
-        if (! empty($this->_image_url)) {
214
-            $token_request_dtls['LOGOIMG'] = $this->_image_url;
215
-        }
216
-        $token_request_dtls = apply_filters(
217
-            'FHEE__EEG_Paypal_Express__set_redirection_info__arguments',
218
-            $token_request_dtls,
219
-            $this
220
-        );
221
-        // Request PayPal token.
222
-        $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment);
223
-        $token_rstatus = $this->_ppExpress_check_response($token_request_response);
224
-        $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args']))
225
-            ? $token_rstatus['args']
226
-            : array();
227
-        if ($token_rstatus['status']) {
228
-            // We got the Token so we may continue with the payment and redirect the client.
229
-            $payment->set_details($response_args);
230
-            $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
231
-            $payment->set_redirect_url(
232
-                $gateway_url
233
-                . '/checkoutnow?useraction=commit&cmd=_express-checkout&token='
234
-                . $response_args['TOKEN']
235
-            );
236
-        } else {
237
-            if (isset($response_args['L_ERRORCODE'])) {
238
-                $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']);
239
-            } else {
240
-                $payment->set_gateway_response(
241
-                    esc_html__(
242
-                        'Error occurred while trying to setup the Express Checkout.',
243
-                        'event_espresso'
244
-                    )
245
-                );
246
-            }
247
-            $payment->set_details($response_args);
248
-            $payment->set_status($this->_pay_model->failed_status());
249
-        }
250
-        return $payment;
251
-    }
252
-
253
-
254
-
255
-    /**
256
-     * @param array           $update_info {
257
-     * @type string           $gateway_txn_id
258
-     * @type string status an EEMI_Payment status
259
-     *                                     }
260
-     * @param EEI_Transaction $transaction
261
-     * @return EEI_Payment
262
-     */
263
-    public function handle_payment_update($update_info, $transaction)
264
-    {
265
-        $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null;
266
-        if ($payment instanceof EEI_Payment) {
267
-            $this->log(array('Return from Authorization' => $update_info), $payment);
268
-            $transaction = $payment->transaction();
269
-            if (! $transaction instanceof EEI_Transaction) {
270
-                $payment->set_gateway_response(
271
-                    esc_html__(
272
-                        'Could not process this payment because it has no associated transaction.',
273
-                        'event_espresso'
274
-                    )
275
-                );
276
-                $payment->set_status($this->_pay_model->failed_status());
277
-                return $payment;
278
-            }
279
-            $primary_registrant = $transaction->primary_registration();
280
-            $payment_details = $payment->details();
281
-            // Check if we still have the token.
282
-            if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
283
-                $payment->set_status($this->_pay_model->failed_status());
284
-                return $payment;
285
-            }
286
-            $cdetails_request_dtls = array(
287
-                'METHOD' => 'GetExpressCheckoutDetails',
288
-                'TOKEN'  => $payment_details['TOKEN'],
289
-            );
290
-            // Request Customer Details.
291
-            $cdetails_request_response = $this->_ppExpress_request(
292
-                $cdetails_request_dtls,
293
-                'Customer Details',
294
-                $payment
295
-            );
296
-            $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response);
297
-            $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']))
298
-                ? $cdetails_rstatus['args']
299
-                : array();
300
-            if ($cdetails_rstatus['status']) {
301
-                // We got the PayerID so now we can Complete the transaction.
302
-                $docheckout_request_dtls = array(
303
-                    'METHOD'                         => 'DoExpressCheckoutPayment',
304
-                    'PAYERID'                        => $cdata_response_args['PAYERID'],
305
-                    'TOKEN'                          => $payment_details['TOKEN'],
306
-                    'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
307
-                    'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
308
-                    'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
309
-                    //EE will blow up if you change this
310
-                    'BUTTONSOURCE'                   => 'EventEspresso_SP',
311
-                );
312
-                 // Include itemized list.
313
-                $itemized_list = $this->itemize_list(
314
-                    $payment,
315
-                    $transaction,
316
-                    $cdata_response_args
317
-                );
318
-                $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list);
319
-                // Payment Checkout/Capture.
320
-                $docheckout_request_response = $this->_ppExpress_request(
321
-                    $docheckout_request_dtls,
322
-                    'Do Payment',
323
-                    $payment
324
-                );
325
-                $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response);
326
-                $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']))
327
-                    ? $docheckout_rstatus['args']
328
-                    : array();
329
-                if ($docheckout_rstatus['status']) {
330
-                    // All is well, payment approved.
331
-                    $primary_registration_code = $primary_registrant instanceof EE_Registration ?
332
-                        $primary_registrant->reg_code()
333
-                        : '';
334
-                    $payment->set_extra_accntng($primary_registration_code);
335
-                    $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT'])
336
-                        ? (float)$docheckout_response_args['PAYMENTINFO_0_AMT']
337
-                        : 0);
338
-                    $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'])
339
-                        ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']
340
-                        : null);
341
-                    $payment->set_details($cdata_response_args);
342
-                    $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK'])
343
-                        ? $docheckout_response_args['PAYMENTINFO_0_ACK']
344
-                        : '');
345
-                    $payment->set_status($this->_pay_model->approved_status());
346
-                } else {
347
-                    if (isset($docheckout_response_args['L_ERRORCODE'])) {
348
-                        $payment->set_gateway_response(
349
-                            $docheckout_response_args['L_ERRORCODE']
350
-                            . '; '
351
-                            . $docheckout_response_args['L_SHORTMESSAGE']
352
-                        );
353
-                    } else {
354
-                        $payment->set_gateway_response(
355
-                            esc_html__(
356
-                                'Error occurred while trying to Capture the funds.',
357
-                                'event_espresso'
358
-                            )
359
-                        );
360
-                    }
361
-                    $payment->set_details($docheckout_response_args);
362
-                    $payment->set_status($this->_pay_model->declined_status());
363
-                }
364
-            } else {
365
-                if (isset($cdata_response_args['L_ERRORCODE'])) {
366
-                    $payment->set_gateway_response(
367
-                        $cdata_response_args['L_ERRORCODE']
368
-                        . '; '
369
-                        . $cdata_response_args['L_SHORTMESSAGE']
370
-                    );
371
-                } else {
372
-                    $payment->set_gateway_response(
373
-                        esc_html__(
374
-                            'Error occurred while trying to get payment Details from PayPal.',
375
-                            'event_espresso'
376
-                        )
377
-                    );
378
-                }
379
-                $payment->set_details($cdata_response_args);
380
-                $payment->set_status($this->_pay_model->failed_status());
381
-            }
382
-        } else {
383
-            $payment->set_gateway_response(
384
-                esc_html__(
385
-                    'Error occurred while trying to process the payment.',
386
-                    'event_espresso'
387
-                )
388
-            );
389
-            $payment->set_status($this->_pay_model->failed_status());
390
-        }
391
-        return $payment;
392
-    }
393
-
394
-
395
-
396
-    /**
397
-     *  Make a list of items that are in the giver transaction.
398
-     *
399
-     * @param EEI_Payment     $payment
400
-     * @param EEI_Transaction $transaction
401
-     * @param array           $request_response_args Data from a previous communication with PP.
402
-     * @return array
403
-     */
404
-    public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array())
405
-    {
406
-        $itemized_list = array();
407
-        // If we have data from a previous communication with PP (on this transaction) we may use that for our list...
408
-        if (
409
-            ! empty($request_response_args)
410
-            && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args)
411
-            && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args)
412
-        ) {
413
-            foreach ($request_response_args as $arg_key => $arg_val) {
414
-                if (
415
-                    strpos($arg_key, 'PAYMENTREQUEST_') !== false
416
-                    && strpos($arg_key, 'NOTIFYURL') === false
417
-                ) {
418
-                    $itemized_list[$arg_key] = $arg_val;
419
-                }
420
-            }
421
-            // If we got only a few Items then something is not right.
422
-            if (count($itemized_list) > 2) {
423
-                return $itemized_list;
424
-            } else {
425
-                if (WP_DEBUG) {
426
-                    throw new EE_Error(
427
-                        sprintf(
428
-                            esc_html__(
429
-                                // @codingStandardsIgnoreStart
430
-                                'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s',
431
-                                // @codingStandardsIgnoreEnd
432
-                                'event_espresso'
433
-                            ),
434
-                            wp_json_encode($itemized_list)
435
-                        )
436
-                    );
437
-                }
438
-                // Reset the list and log an error, maybe allow to try and generate a new list (below).
439
-                $itemized_list = array();
440
-                $this->log(
441
-                    array(
442
-                        esc_html__(
443
-                            'Could not generate a proper item list with:',
444
-                            'event_espresso'
445
-                        ) => $request_response_args
446
-                    ),
447
-                    $payment
448
-                );
449
-            }
450
-        }
451
-        // ...otherwise we generate a new list for this transaction.
452
-        if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
453
-            $item_num = 0;
454
-            $itemized_sum = 0;
455
-            $total_line_items = $transaction->total_line_item();
456
-            // Go through each item in the list.
457
-            foreach ($total_line_items->get_items() as $line_item) {
458
-                if ($line_item instanceof EE_Line_Item) {
459
-                    // PayPal doesn't like line items with 0.00 amount, so we may skip those.
460
-                    if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) {
461
-                        continue;
462
-                    }
463
-                    $unit_price = $line_item->unit_price();
464
-                    $line_item_quantity = $line_item->quantity();
465
-                    // This is a discount.
466
-                    if ($line_item->is_percent()) {
467
-                        $unit_price = $line_item->total();
468
-                        $line_item_quantity = 1;
469
-                    }
470
-                    // Item Name.
471
-                    $itemized_list['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut(
472
-                        $this->_format_line_item_name($line_item, $payment),
473
-                        0,
474
-                        127
475
-                    );
476
-                    // Item description.
477
-                    $itemized_list['L_PAYMENTREQUEST_0_DESC' . $item_num] = mb_strcut(
478
-                        $this->_format_line_item_desc($line_item, $payment),
479
-                        0,
480
-                        127
481
-                    );
482
-                    // Cost of individual item.
483
-                    $itemized_list['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency($unit_price);
484
-                    // Item Number.
485
-                    $itemized_list['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1;
486
-                    // Item quantity.
487
-                    $itemized_list['L_PAYMENTREQUEST_0_QTY' . $item_num] = $line_item_quantity;
488
-                    // Digital item is sold.
489
-                    $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical';
490
-                    $itemized_sum += $line_item->total();
491
-                    ++$item_num;
492
-                }
493
-            }
494
-            // Item's sales S/H and tax amount.
495
-            $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total();
496
-            $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax();
497
-            $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
498
-            $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
499
-            $itemized_sum_diff_from_txn_total = round(
500
-                $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(),
501
-                2
502
-            );
503
-            // If we were not able to recognize some item like promotion, surcharge or cancellation,
504
-            // add the difference as an extra line item.
505
-            if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
506
-                // Item Name.
507
-                $itemized_list['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut(
508
-                    esc_html__(
509
-                        'Other (promotion/surcharge/cancellation)',
510
-                        'event_espresso'
511
-                    ),
512
-                    0,
513
-                    127
514
-                );
515
-                // Item description.
516
-                $itemized_list['L_PAYMENTREQUEST_0_DESC' . $item_num] = '';
517
-                // Cost of individual item.
518
-                $itemized_list['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency(
519
-                    $itemized_sum_diff_from_txn_total
520
-                );
521
-                // Item Number.
522
-                $itemized_list['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1;
523
-                // Item quantity.
524
-                $itemized_list['L_PAYMENTREQUEST_0_QTY' . $item_num] = 1;
525
-                // Digital item is sold.
526
-                $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical';
527
-                $item_num++;
528
-            }
529
-        } else {
530
-            // Just one Item.
531
-            // Item Name.
532
-            $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut(
533
-                $this->_format_partial_payment_line_item_name($payment),
534
-                0,
535
-                127
536
-            );
537
-            // Item description.
538
-            $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut(
539
-                $this->_format_partial_payment_line_item_desc($payment),
540
-                0,
541
-                127
542
-            );
543
-            // Cost of individual item.
544
-            $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency($payment->amount());
545
-            // Item Number.
546
-            $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1;
547
-            // Item quantity.
548
-            $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1;
549
-            // Digital item is sold.
550
-            $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical';
551
-            // Item's sales S/H and tax amount.
552
-            $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency($payment->amount());
553
-            $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0';
554
-            $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
555
-            $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
556
-        }
557
-        return $itemized_list;
558
-    }
559
-
560
-
561
-
562
-    /**
563
-     *  Make the Express checkout request.
564
-     *
565
-     * @param array       $request_params
566
-     * @param string      $request_text
567
-     * @param EEI_Payment $payment
568
-     * @return mixed
569
-     */
570
-    public function _ppExpress_request($request_params, $request_text, $payment)
571
-    {
572
-        $request_dtls = array(
573
-            'VERSION'   => '204.0',
574
-            'USER'      => urlencode($this->_api_username),
575
-            'PWD'       => urlencode($this->_api_password),
576
-            'SIGNATURE' => urlencode($this->_api_signature),
577
-        );
578
-        $dtls = array_merge($request_dtls, $request_params);
579
-        $this->_log_clean_request($dtls, $payment, $request_text . ' Request');
580
-        // Request Customer Details.
581
-        $request_response = wp_remote_post(
582
-            $this->_base_gateway_url,
583
-            array(
584
-                'method'      => 'POST',
585
-                'timeout'     => 45,
586
-                'httpversion' => '1.1',
587
-                'cookies'     => array(),
588
-                'headers'     => array(),
589
-                'body'        => http_build_query($dtls),
590
-            )
591
-        );
592
-        // Log the response.
593
-        $this->log(array($request_text . ' Response' => $request_response), $payment);
594
-        return $request_response;
595
-    }
596
-
597
-
598
-
599
-    /**
600
-     *  Check the response status.
601
-     *
602
-     * @param mixed $request_response
603
-     * @return array
604
-     */
605
-    public function _ppExpress_check_response($request_response)
606
-    {
607
-        if (is_wp_error($request_response) || empty($request_response['body'])) {
608
-            // If we got here then there was an error in this request.
609
-            return array('status' => false, 'args' => $request_response);
610
-        }
611
-        $response_args = array();
612
-        parse_str(urldecode($request_response['body']), $response_args);
613
-        if (! isset($response_args['ACK'])) {
614
-            return array('status' => false, 'args' => $request_response);
615
-        }
616
-        if (
617
-            (
618
-                isset($response_args['PAYERID'])
619
-                || isset($response_args['TOKEN'])
620
-                || isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
621
-                || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
622
-            )
623
-            && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true)
624
-        ) {
625
-            // Response status OK, return response parameters for further processing.
626
-            return array('status' => true, 'args' => $response_args);
627
-        }
628
-        $errors = $this->_get_errors($response_args);
629
-        return array('status' => false, 'args' => $errors);
630
-    }
631
-
632
-
633
-
634
-    /**
635
-     *  Log a "Cleared" request.
636
-     *
637
-     * @param array       $request
638
-     * @param EEI_Payment $payment
639
-     * @param string      $info
640
-     * @return void
641
-     */
642
-    private function _log_clean_request($request, $payment, $info)
643
-    {
644
-        $cleaned_request_data = $request;
645
-        unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']);
646
-        $this->log(array($info => $cleaned_request_data), $payment);
647
-    }
648
-
649
-
650
-
651
-    /**
652
-     *  Get error from the response data.
653
-     *
654
-     * @param array $data_array
655
-     * @return array
656
-     */
657
-    private function _get_errors($data_array)
658
-    {
659
-        $errors = array();
660
-        $n = 0;
661
-        while (isset($data_array["L_ERRORCODE{$n}"])) {
662
-            $l_error_code = isset($data_array["L_ERRORCODE{$n}"])
663
-                ? $data_array["L_ERRORCODE{$n}"]
664
-                : '';
665
-            $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"])
666
-                ? $data_array["L_SEVERITYCODE{$n}"]
667
-                : '';
668
-            $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"])
669
-                ? $data_array["L_SHORTMESSAGE{$n}"]
670
-                : '';
671
-            $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"])
672
-                ? $data_array["L_LONGMESSAGE{$n}"]
673
-                : '';
674
-            if ($n === 0) {
675
-                $errors = array(
676
-                    'L_ERRORCODE'    => $l_error_code,
677
-                    'L_SHORTMESSAGE' => $l_short_message,
678
-                    'L_LONGMESSAGE'  => $l_long_message,
679
-                    'L_SEVERITYCODE' => $l_severity_code,
680
-                );
681
-            } else {
682
-                $errors['L_ERRORCODE'] .= ', ' . $l_error_code;
683
-                $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
684
-                $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
685
-                $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
686
-            }
687
-            $n++;
688
-        }
689
-        return $errors;
690
-    }
35
+	/**
36
+	 * Merchant API Username.
37
+	 *
38
+	 * @var string
39
+	 */
40
+	protected $_api_username;
41
+
42
+	/**
43
+	 * Merchant API Password.
44
+	 *
45
+	 * @var string
46
+	 */
47
+	protected $_api_password;
48
+
49
+	/**
50
+	 * API Signature.
51
+	 *
52
+	 * @var string
53
+	 */
54
+	protected $_api_signature;
55
+
56
+	/**
57
+	 * Request Shipping address on PP checkout page.
58
+	 *
59
+	 * @var string
60
+	 */
61
+	protected $_request_shipping_addr;
62
+
63
+	/**
64
+	 * Business/personal logo.
65
+	 *
66
+	 * @var string
67
+	 */
68
+	protected $_image_url;
69
+
70
+	/**
71
+	 * gateway URL variable
72
+	 *
73
+	 * @var string
74
+	 */
75
+	protected $_base_gateway_url = '';
76
+
77
+
78
+
79
+	/**
80
+	 * EEG_Paypal_Express constructor.
81
+	 */
82
+	public function __construct()
83
+	{
84
+		$this->_currencies_supported = array(
85
+			'USD',
86
+			'AUD',
87
+			'BRL',
88
+			'CAD',
89
+			'CZK',
90
+			'DKK',
91
+			'EUR',
92
+			'HKD',
93
+			'HUF',
94
+			'ILS',
95
+			'JPY',
96
+			'MYR',
97
+			'MXN',
98
+			'NOK',
99
+			'NZD',
100
+			'PHP',
101
+			'PLN',
102
+			'GBP',
103
+			'RUB',
104
+			'SGD',
105
+			'SEK',
106
+			'CHF',
107
+			'TWD',
108
+			'THB',
109
+			'TRY',
110
+		);
111
+		parent::__construct();
112
+	}
113
+
114
+
115
+
116
+	/**
117
+	 * Sets the gateway URL variable based on whether debug mode is enabled or not.
118
+	 *
119
+	 * @param array $settings_array
120
+	 */
121
+	public function set_settings($settings_array)
122
+	{
123
+		parent::set_settings($settings_array);
124
+		// Redirect URL.
125
+		$this->_base_gateway_url = $this->_debug_mode
126
+			? 'https://api-3t.sandbox.paypal.com/nvp'
127
+			: 'https://api-3t.paypal.com/nvp';
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @param EEI_Payment $payment
134
+	 * @param array       $billing_info
135
+	 * @param string      $return_url
136
+	 * @param string      $notify_url
137
+	 * @param string      $cancel_url
138
+	 * @return \EE_Payment|\EEI_Payment
139
+	 * @throws \EE_Error
140
+	 */
141
+	public function set_redirection_info(
142
+		$payment,
143
+		$billing_info = array(),
144
+		$return_url = null,
145
+		$notify_url = null,
146
+		$cancel_url = null
147
+	) {
148
+		if (! $payment instanceof EEI_Payment) {
149
+			$payment->set_gateway_response(
150
+				esc_html__(
151
+					'Error. No associated payment was found.',
152
+					'event_espresso'
153
+				)
154
+			);
155
+			$payment->set_status($this->_pay_model->failed_status());
156
+			return $payment;
157
+		}
158
+		$transaction = $payment->transaction();
159
+		if (! $transaction instanceof EEI_Transaction) {
160
+			$payment->set_gateway_response(
161
+				esc_html__(
162
+					'Could not process this payment because it has no associated transaction.',
163
+					'event_espresso'
164
+				)
165
+			);
166
+			$payment->set_status($this->_pay_model->failed_status());
167
+			return $payment;
168
+		}
169
+		$order_description = mb_strcut($this->_format_order_description($payment), 0, 127);
170
+		$primary_registration = $transaction->primary_registration();
171
+		$primary_attendee = $primary_registration instanceof EE_Registration
172
+			? $primary_registration->attendee()
173
+			: false;
174
+		$locale = explode('-', get_bloginfo('language'));
175
+		// Gather request parameters.
176
+		$token_request_dtls = array(
177
+			'METHOD'                         => 'SetExpressCheckout',
178
+			'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
179
+			'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
180
+			'PAYMENTREQUEST_0_DESC'          => $order_description,
181
+			'RETURNURL'                      => $return_url,
182
+			'CANCELURL'                      => $cancel_url,
183
+			'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
184
+			// Buyer does not need to create a PayPal account to check out.
185
+			// This is referred to as PayPal Account Optional.
186
+			'SOLUTIONTYPE'                   => 'Sole',
187
+			//EE will blow up if you change this
188
+			'BUTTONSOURCE'                   => 'EventEspresso_SP',
189
+			// Locale of the pages displayed by PayPal during Express Checkout.
190
+			'LOCALECODE'                     => $locale[1]
191
+		);
192
+		// Show itemized list.
193
+		$itemized_list = $this->itemize_list($payment, $transaction);
194
+		$token_request_dtls = array_merge($token_request_dtls, $itemized_list);
195
+		// Automatically filling out shipping and contact information.
196
+		if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) {
197
+			// If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
198
+			$token_request_dtls['NOSHIPPING'] = '2';
199
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address();
200
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2();
201
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city();
202
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev();
203
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID();
204
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
205
+			$token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
206
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
207
+		} elseif (! $this->_request_shipping_addr) {
208
+			// Do not request shipping details on the PP Checkout page.
209
+			$token_request_dtls['NOSHIPPING'] = '1';
210
+			$token_request_dtls['REQCONFIRMSHIPPING'] = '0';
211
+		}
212
+		// Used a business/personal logo on the PayPal page.
213
+		if (! empty($this->_image_url)) {
214
+			$token_request_dtls['LOGOIMG'] = $this->_image_url;
215
+		}
216
+		$token_request_dtls = apply_filters(
217
+			'FHEE__EEG_Paypal_Express__set_redirection_info__arguments',
218
+			$token_request_dtls,
219
+			$this
220
+		);
221
+		// Request PayPal token.
222
+		$token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment);
223
+		$token_rstatus = $this->_ppExpress_check_response($token_request_response);
224
+		$response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args']))
225
+			? $token_rstatus['args']
226
+			: array();
227
+		if ($token_rstatus['status']) {
228
+			// We got the Token so we may continue with the payment and redirect the client.
229
+			$payment->set_details($response_args);
230
+			$gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
231
+			$payment->set_redirect_url(
232
+				$gateway_url
233
+				. '/checkoutnow?useraction=commit&cmd=_express-checkout&token='
234
+				. $response_args['TOKEN']
235
+			);
236
+		} else {
237
+			if (isset($response_args['L_ERRORCODE'])) {
238
+				$payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']);
239
+			} else {
240
+				$payment->set_gateway_response(
241
+					esc_html__(
242
+						'Error occurred while trying to setup the Express Checkout.',
243
+						'event_espresso'
244
+					)
245
+				);
246
+			}
247
+			$payment->set_details($response_args);
248
+			$payment->set_status($this->_pay_model->failed_status());
249
+		}
250
+		return $payment;
251
+	}
252
+
253
+
254
+
255
+	/**
256
+	 * @param array           $update_info {
257
+	 * @type string           $gateway_txn_id
258
+	 * @type string status an EEMI_Payment status
259
+	 *                                     }
260
+	 * @param EEI_Transaction $transaction
261
+	 * @return EEI_Payment
262
+	 */
263
+	public function handle_payment_update($update_info, $transaction)
264
+	{
265
+		$payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null;
266
+		if ($payment instanceof EEI_Payment) {
267
+			$this->log(array('Return from Authorization' => $update_info), $payment);
268
+			$transaction = $payment->transaction();
269
+			if (! $transaction instanceof EEI_Transaction) {
270
+				$payment->set_gateway_response(
271
+					esc_html__(
272
+						'Could not process this payment because it has no associated transaction.',
273
+						'event_espresso'
274
+					)
275
+				);
276
+				$payment->set_status($this->_pay_model->failed_status());
277
+				return $payment;
278
+			}
279
+			$primary_registrant = $transaction->primary_registration();
280
+			$payment_details = $payment->details();
281
+			// Check if we still have the token.
282
+			if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
283
+				$payment->set_status($this->_pay_model->failed_status());
284
+				return $payment;
285
+			}
286
+			$cdetails_request_dtls = array(
287
+				'METHOD' => 'GetExpressCheckoutDetails',
288
+				'TOKEN'  => $payment_details['TOKEN'],
289
+			);
290
+			// Request Customer Details.
291
+			$cdetails_request_response = $this->_ppExpress_request(
292
+				$cdetails_request_dtls,
293
+				'Customer Details',
294
+				$payment
295
+			);
296
+			$cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response);
297
+			$cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']))
298
+				? $cdetails_rstatus['args']
299
+				: array();
300
+			if ($cdetails_rstatus['status']) {
301
+				// We got the PayerID so now we can Complete the transaction.
302
+				$docheckout_request_dtls = array(
303
+					'METHOD'                         => 'DoExpressCheckoutPayment',
304
+					'PAYERID'                        => $cdata_response_args['PAYERID'],
305
+					'TOKEN'                          => $payment_details['TOKEN'],
306
+					'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
307
+					'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
308
+					'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
309
+					//EE will blow up if you change this
310
+					'BUTTONSOURCE'                   => 'EventEspresso_SP',
311
+				);
312
+				 // Include itemized list.
313
+				$itemized_list = $this->itemize_list(
314
+					$payment,
315
+					$transaction,
316
+					$cdata_response_args
317
+				);
318
+				$docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list);
319
+				// Payment Checkout/Capture.
320
+				$docheckout_request_response = $this->_ppExpress_request(
321
+					$docheckout_request_dtls,
322
+					'Do Payment',
323
+					$payment
324
+				);
325
+				$docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response);
326
+				$docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']))
327
+					? $docheckout_rstatus['args']
328
+					: array();
329
+				if ($docheckout_rstatus['status']) {
330
+					// All is well, payment approved.
331
+					$primary_registration_code = $primary_registrant instanceof EE_Registration ?
332
+						$primary_registrant->reg_code()
333
+						: '';
334
+					$payment->set_extra_accntng($primary_registration_code);
335
+					$payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT'])
336
+						? (float)$docheckout_response_args['PAYMENTINFO_0_AMT']
337
+						: 0);
338
+					$payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'])
339
+						? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']
340
+						: null);
341
+					$payment->set_details($cdata_response_args);
342
+					$payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK'])
343
+						? $docheckout_response_args['PAYMENTINFO_0_ACK']
344
+						: '');
345
+					$payment->set_status($this->_pay_model->approved_status());
346
+				} else {
347
+					if (isset($docheckout_response_args['L_ERRORCODE'])) {
348
+						$payment->set_gateway_response(
349
+							$docheckout_response_args['L_ERRORCODE']
350
+							. '; '
351
+							. $docheckout_response_args['L_SHORTMESSAGE']
352
+						);
353
+					} else {
354
+						$payment->set_gateway_response(
355
+							esc_html__(
356
+								'Error occurred while trying to Capture the funds.',
357
+								'event_espresso'
358
+							)
359
+						);
360
+					}
361
+					$payment->set_details($docheckout_response_args);
362
+					$payment->set_status($this->_pay_model->declined_status());
363
+				}
364
+			} else {
365
+				if (isset($cdata_response_args['L_ERRORCODE'])) {
366
+					$payment->set_gateway_response(
367
+						$cdata_response_args['L_ERRORCODE']
368
+						. '; '
369
+						. $cdata_response_args['L_SHORTMESSAGE']
370
+					);
371
+				} else {
372
+					$payment->set_gateway_response(
373
+						esc_html__(
374
+							'Error occurred while trying to get payment Details from PayPal.',
375
+							'event_espresso'
376
+						)
377
+					);
378
+				}
379
+				$payment->set_details($cdata_response_args);
380
+				$payment->set_status($this->_pay_model->failed_status());
381
+			}
382
+		} else {
383
+			$payment->set_gateway_response(
384
+				esc_html__(
385
+					'Error occurred while trying to process the payment.',
386
+					'event_espresso'
387
+				)
388
+			);
389
+			$payment->set_status($this->_pay_model->failed_status());
390
+		}
391
+		return $payment;
392
+	}
393
+
394
+
395
+
396
+	/**
397
+	 *  Make a list of items that are in the giver transaction.
398
+	 *
399
+	 * @param EEI_Payment     $payment
400
+	 * @param EEI_Transaction $transaction
401
+	 * @param array           $request_response_args Data from a previous communication with PP.
402
+	 * @return array
403
+	 */
404
+	public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array())
405
+	{
406
+		$itemized_list = array();
407
+		// If we have data from a previous communication with PP (on this transaction) we may use that for our list...
408
+		if (
409
+			! empty($request_response_args)
410
+			&& array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args)
411
+			&& array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args)
412
+		) {
413
+			foreach ($request_response_args as $arg_key => $arg_val) {
414
+				if (
415
+					strpos($arg_key, 'PAYMENTREQUEST_') !== false
416
+					&& strpos($arg_key, 'NOTIFYURL') === false
417
+				) {
418
+					$itemized_list[$arg_key] = $arg_val;
419
+				}
420
+			}
421
+			// If we got only a few Items then something is not right.
422
+			if (count($itemized_list) > 2) {
423
+				return $itemized_list;
424
+			} else {
425
+				if (WP_DEBUG) {
426
+					throw new EE_Error(
427
+						sprintf(
428
+							esc_html__(
429
+								// @codingStandardsIgnoreStart
430
+								'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s',
431
+								// @codingStandardsIgnoreEnd
432
+								'event_espresso'
433
+							),
434
+							wp_json_encode($itemized_list)
435
+						)
436
+					);
437
+				}
438
+				// Reset the list and log an error, maybe allow to try and generate a new list (below).
439
+				$itemized_list = array();
440
+				$this->log(
441
+					array(
442
+						esc_html__(
443
+							'Could not generate a proper item list with:',
444
+							'event_espresso'
445
+						) => $request_response_args
446
+					),
447
+					$payment
448
+				);
449
+			}
450
+		}
451
+		// ...otherwise we generate a new list for this transaction.
452
+		if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
453
+			$item_num = 0;
454
+			$itemized_sum = 0;
455
+			$total_line_items = $transaction->total_line_item();
456
+			// Go through each item in the list.
457
+			foreach ($total_line_items->get_items() as $line_item) {
458
+				if ($line_item instanceof EE_Line_Item) {
459
+					// PayPal doesn't like line items with 0.00 amount, so we may skip those.
460
+					if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) {
461
+						continue;
462
+					}
463
+					$unit_price = $line_item->unit_price();
464
+					$line_item_quantity = $line_item->quantity();
465
+					// This is a discount.
466
+					if ($line_item->is_percent()) {
467
+						$unit_price = $line_item->total();
468
+						$line_item_quantity = 1;
469
+					}
470
+					// Item Name.
471
+					$itemized_list['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut(
472
+						$this->_format_line_item_name($line_item, $payment),
473
+						0,
474
+						127
475
+					);
476
+					// Item description.
477
+					$itemized_list['L_PAYMENTREQUEST_0_DESC' . $item_num] = mb_strcut(
478
+						$this->_format_line_item_desc($line_item, $payment),
479
+						0,
480
+						127
481
+					);
482
+					// Cost of individual item.
483
+					$itemized_list['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency($unit_price);
484
+					// Item Number.
485
+					$itemized_list['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1;
486
+					// Item quantity.
487
+					$itemized_list['L_PAYMENTREQUEST_0_QTY' . $item_num] = $line_item_quantity;
488
+					// Digital item is sold.
489
+					$itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical';
490
+					$itemized_sum += $line_item->total();
491
+					++$item_num;
492
+				}
493
+			}
494
+			// Item's sales S/H and tax amount.
495
+			$itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total();
496
+			$itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax();
497
+			$itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
498
+			$itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
499
+			$itemized_sum_diff_from_txn_total = round(
500
+				$transaction->total() - $itemized_sum - $total_line_items->get_total_tax(),
501
+				2
502
+			);
503
+			// If we were not able to recognize some item like promotion, surcharge or cancellation,
504
+			// add the difference as an extra line item.
505
+			if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
506
+				// Item Name.
507
+				$itemized_list['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut(
508
+					esc_html__(
509
+						'Other (promotion/surcharge/cancellation)',
510
+						'event_espresso'
511
+					),
512
+					0,
513
+					127
514
+				);
515
+				// Item description.
516
+				$itemized_list['L_PAYMENTREQUEST_0_DESC' . $item_num] = '';
517
+				// Cost of individual item.
518
+				$itemized_list['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency(
519
+					$itemized_sum_diff_from_txn_total
520
+				);
521
+				// Item Number.
522
+				$itemized_list['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1;
523
+				// Item quantity.
524
+				$itemized_list['L_PAYMENTREQUEST_0_QTY' . $item_num] = 1;
525
+				// Digital item is sold.
526
+				$itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical';
527
+				$item_num++;
528
+			}
529
+		} else {
530
+			// Just one Item.
531
+			// Item Name.
532
+			$itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut(
533
+				$this->_format_partial_payment_line_item_name($payment),
534
+				0,
535
+				127
536
+			);
537
+			// Item description.
538
+			$itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut(
539
+				$this->_format_partial_payment_line_item_desc($payment),
540
+				0,
541
+				127
542
+			);
543
+			// Cost of individual item.
544
+			$itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency($payment->amount());
545
+			// Item Number.
546
+			$itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1;
547
+			// Item quantity.
548
+			$itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1;
549
+			// Digital item is sold.
550
+			$itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical';
551
+			// Item's sales S/H and tax amount.
552
+			$itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency($payment->amount());
553
+			$itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0';
554
+			$itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
555
+			$itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
556
+		}
557
+		return $itemized_list;
558
+	}
559
+
560
+
561
+
562
+	/**
563
+	 *  Make the Express checkout request.
564
+	 *
565
+	 * @param array       $request_params
566
+	 * @param string      $request_text
567
+	 * @param EEI_Payment $payment
568
+	 * @return mixed
569
+	 */
570
+	public function _ppExpress_request($request_params, $request_text, $payment)
571
+	{
572
+		$request_dtls = array(
573
+			'VERSION'   => '204.0',
574
+			'USER'      => urlencode($this->_api_username),
575
+			'PWD'       => urlencode($this->_api_password),
576
+			'SIGNATURE' => urlencode($this->_api_signature),
577
+		);
578
+		$dtls = array_merge($request_dtls, $request_params);
579
+		$this->_log_clean_request($dtls, $payment, $request_text . ' Request');
580
+		// Request Customer Details.
581
+		$request_response = wp_remote_post(
582
+			$this->_base_gateway_url,
583
+			array(
584
+				'method'      => 'POST',
585
+				'timeout'     => 45,
586
+				'httpversion' => '1.1',
587
+				'cookies'     => array(),
588
+				'headers'     => array(),
589
+				'body'        => http_build_query($dtls),
590
+			)
591
+		);
592
+		// Log the response.
593
+		$this->log(array($request_text . ' Response' => $request_response), $payment);
594
+		return $request_response;
595
+	}
596
+
597
+
598
+
599
+	/**
600
+	 *  Check the response status.
601
+	 *
602
+	 * @param mixed $request_response
603
+	 * @return array
604
+	 */
605
+	public function _ppExpress_check_response($request_response)
606
+	{
607
+		if (is_wp_error($request_response) || empty($request_response['body'])) {
608
+			// If we got here then there was an error in this request.
609
+			return array('status' => false, 'args' => $request_response);
610
+		}
611
+		$response_args = array();
612
+		parse_str(urldecode($request_response['body']), $response_args);
613
+		if (! isset($response_args['ACK'])) {
614
+			return array('status' => false, 'args' => $request_response);
615
+		}
616
+		if (
617
+			(
618
+				isset($response_args['PAYERID'])
619
+				|| isset($response_args['TOKEN'])
620
+				|| isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
621
+				|| (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
622
+			)
623
+			&& in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true)
624
+		) {
625
+			// Response status OK, return response parameters for further processing.
626
+			return array('status' => true, 'args' => $response_args);
627
+		}
628
+		$errors = $this->_get_errors($response_args);
629
+		return array('status' => false, 'args' => $errors);
630
+	}
631
+
632
+
633
+
634
+	/**
635
+	 *  Log a "Cleared" request.
636
+	 *
637
+	 * @param array       $request
638
+	 * @param EEI_Payment $payment
639
+	 * @param string      $info
640
+	 * @return void
641
+	 */
642
+	private function _log_clean_request($request, $payment, $info)
643
+	{
644
+		$cleaned_request_data = $request;
645
+		unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']);
646
+		$this->log(array($info => $cleaned_request_data), $payment);
647
+	}
648
+
649
+
650
+
651
+	/**
652
+	 *  Get error from the response data.
653
+	 *
654
+	 * @param array $data_array
655
+	 * @return array
656
+	 */
657
+	private function _get_errors($data_array)
658
+	{
659
+		$errors = array();
660
+		$n = 0;
661
+		while (isset($data_array["L_ERRORCODE{$n}"])) {
662
+			$l_error_code = isset($data_array["L_ERRORCODE{$n}"])
663
+				? $data_array["L_ERRORCODE{$n}"]
664
+				: '';
665
+			$l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"])
666
+				? $data_array["L_SEVERITYCODE{$n}"]
667
+				: '';
668
+			$l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"])
669
+				? $data_array["L_SHORTMESSAGE{$n}"]
670
+				: '';
671
+			$l_long_message = isset($data_array["L_LONGMESSAGE{$n}"])
672
+				? $data_array["L_LONGMESSAGE{$n}"]
673
+				: '';
674
+			if ($n === 0) {
675
+				$errors = array(
676
+					'L_ERRORCODE'    => $l_error_code,
677
+					'L_SHORTMESSAGE' => $l_short_message,
678
+					'L_LONGMESSAGE'  => $l_long_message,
679
+					'L_SEVERITYCODE' => $l_severity_code,
680
+				);
681
+			} else {
682
+				$errors['L_ERRORCODE'] .= ', ' . $l_error_code;
683
+				$errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
684
+				$errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
685
+				$errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
686
+			}
687
+			$n++;
688
+		}
689
+		return $errors;
690
+	}
691 691
 
692 692
 }
693 693
 // End of file EEG_Paypal_Express.gateway.php
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('NO direct script access allowed');
3 3
 }
4 4
 
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * ----------------------------------------------
16 16
  */
17 17
 //Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP
18
-if (! function_exists('mb_strcut')) {
18
+if ( ! function_exists('mb_strcut')) {
19 19
     /**
20 20
      * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
21 21
      * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
         $notify_url = null,
146 146
         $cancel_url = null
147 147
     ) {
148
-        if (! $payment instanceof EEI_Payment) {
148
+        if ( ! $payment instanceof EEI_Payment) {
149 149
             $payment->set_gateway_response(
150 150
                 esc_html__(
151 151
                     'Error. No associated payment was found.',
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
             return $payment;
157 157
         }
158 158
         $transaction = $payment->transaction();
159
-        if (! $transaction instanceof EEI_Transaction) {
159
+        if ( ! $transaction instanceof EEI_Transaction) {
160 160
             $payment->set_gateway_response(
161 161
                 esc_html__(
162 162
                     'Could not process this payment because it has no associated transaction.',
@@ -204,13 +204,13 @@  discard block
 block discarded – undo
204 204
             $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
205 205
             $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
206 206
             $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
207
-        } elseif (! $this->_request_shipping_addr) {
207
+        } elseif ( ! $this->_request_shipping_addr) {
208 208
             // Do not request shipping details on the PP Checkout page.
209 209
             $token_request_dtls['NOSHIPPING'] = '1';
210 210
             $token_request_dtls['REQCONFIRMSHIPPING'] = '0';
211 211
         }
212 212
         // Used a business/personal logo on the PayPal page.
213
-        if (! empty($this->_image_url)) {
213
+        if ( ! empty($this->_image_url)) {
214 214
             $token_request_dtls['LOGOIMG'] = $this->_image_url;
215 215
         }
216 216
         $token_request_dtls = apply_filters(
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
             );
236 236
         } else {
237 237
             if (isset($response_args['L_ERRORCODE'])) {
238
-                $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']);
238
+                $payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']);
239 239
             } else {
240 240
                 $payment->set_gateway_response(
241 241
                     esc_html__(
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
         if ($payment instanceof EEI_Payment) {
267 267
             $this->log(array('Return from Authorization' => $update_info), $payment);
268 268
             $transaction = $payment->transaction();
269
-            if (! $transaction instanceof EEI_Transaction) {
269
+            if ( ! $transaction instanceof EEI_Transaction) {
270 270
                 $payment->set_gateway_response(
271 271
                     esc_html__(
272 272
                         'Could not process this payment because it has no associated transaction.',
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
             $primary_registrant = $transaction->primary_registration();
280 280
             $payment_details = $payment->details();
281 281
             // Check if we still have the token.
282
-            if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
282
+            if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
283 283
                 $payment->set_status($this->_pay_model->failed_status());
284 284
                 return $payment;
285 285
             }
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
                         : '';
334 334
                     $payment->set_extra_accntng($primary_registration_code);
335 335
                     $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT'])
336
-                        ? (float)$docheckout_response_args['PAYMENTINFO_0_AMT']
336
+                        ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT']
337 337
                         : 0);
338 338
                     $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'])
339 339
                         ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']
@@ -468,25 +468,25 @@  discard block
 block discarded – undo
468 468
                         $line_item_quantity = 1;
469 469
                     }
470 470
                     // Item Name.
471
-                    $itemized_list['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut(
471
+                    $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut(
472 472
                         $this->_format_line_item_name($line_item, $payment),
473 473
                         0,
474 474
                         127
475 475
                     );
476 476
                     // Item description.
477
-                    $itemized_list['L_PAYMENTREQUEST_0_DESC' . $item_num] = mb_strcut(
477
+                    $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = mb_strcut(
478 478
                         $this->_format_line_item_desc($line_item, $payment),
479 479
                         0,
480 480
                         127
481 481
                     );
482 482
                     // Cost of individual item.
483
-                    $itemized_list['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency($unit_price);
483
+                    $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($unit_price);
484 484
                     // Item Number.
485
-                    $itemized_list['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1;
485
+                    $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
486 486
                     // Item quantity.
487
-                    $itemized_list['L_PAYMENTREQUEST_0_QTY' . $item_num] = $line_item_quantity;
487
+                    $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = $line_item_quantity;
488 488
                     // Digital item is sold.
489
-                    $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical';
489
+                    $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical';
490 490
                     $itemized_sum += $line_item->total();
491 491
                     ++$item_num;
492 492
                 }
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
             // add the difference as an extra line item.
505 505
             if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
506 506
                 // Item Name.
507
-                $itemized_list['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut(
507
+                $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut(
508 508
                     esc_html__(
509 509
                         'Other (promotion/surcharge/cancellation)',
510 510
                         'event_espresso'
@@ -513,17 +513,17 @@  discard block
 block discarded – undo
513 513
                     127
514 514
                 );
515 515
                 // Item description.
516
-                $itemized_list['L_PAYMENTREQUEST_0_DESC' . $item_num] = '';
516
+                $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = '';
517 517
                 // Cost of individual item.
518
-                $itemized_list['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency(
518
+                $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency(
519 519
                     $itemized_sum_diff_from_txn_total
520 520
                 );
521 521
                 // Item Number.
522
-                $itemized_list['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1;
522
+                $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
523 523
                 // Item quantity.
524
-                $itemized_list['L_PAYMENTREQUEST_0_QTY' . $item_num] = 1;
524
+                $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1;
525 525
                 // Digital item is sold.
526
-                $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical';
526
+                $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical';
527 527
                 $item_num++;
528 528
             }
529 529
         } else {
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
             'SIGNATURE' => urlencode($this->_api_signature),
577 577
         );
578 578
         $dtls = array_merge($request_dtls, $request_params);
579
-        $this->_log_clean_request($dtls, $payment, $request_text . ' Request');
579
+        $this->_log_clean_request($dtls, $payment, $request_text.' Request');
580 580
         // Request Customer Details.
581 581
         $request_response = wp_remote_post(
582 582
             $this->_base_gateway_url,
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
             )
591 591
         );
592 592
         // Log the response.
593
-        $this->log(array($request_text . ' Response' => $request_response), $payment);
593
+        $this->log(array($request_text.' Response' => $request_response), $payment);
594 594
         return $request_response;
595 595
     }
596 596
 
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
         }
611 611
         $response_args = array();
612 612
         parse_str(urldecode($request_response['body']), $response_args);
613
-        if (! isset($response_args['ACK'])) {
613
+        if ( ! isset($response_args['ACK'])) {
614 614
             return array('status' => false, 'args' => $request_response);
615 615
         }
616 616
         if (
@@ -679,10 +679,10 @@  discard block
 block discarded – undo
679 679
                     'L_SEVERITYCODE' => $l_severity_code,
680 680
                 );
681 681
             } else {
682
-                $errors['L_ERRORCODE'] .= ', ' . $l_error_code;
683
-                $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
684
-                $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
685
-                $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
682
+                $errors['L_ERRORCODE'] .= ', '.$l_error_code;
683
+                $errors['L_SHORTMESSAGE'] .= ', '.$l_short_message;
684
+                $errors['L_LONGMESSAGE'] .= ', '.$l_long_message;
685
+                $errors['L_SEVERITYCODE'] .= ', '.$l_severity_code;
686 686
             }
687 687
             $n++;
688 688
         }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -38,217 +38,217 @@
 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
 
64 64
 } else {
65
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
-        /**
68
-         * espresso_minimum_php_version_error
69
-         *
70
-         * @return void
71
-         */
72
-        function espresso_minimum_php_version_error()
73
-        {
74
-            ?>
65
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
+		/**
68
+		 * espresso_minimum_php_version_error
69
+		 *
70
+		 * @return void
71
+		 */
72
+		function espresso_minimum_php_version_error()
73
+		{
74
+			?>
75 75
             <div class="error">
76 76
                 <p>
77 77
                     <?php
78
-                    printf(
79
-                        esc_html__(
80
-                            '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.',
81
-                            'event_espresso'
82
-                        ),
83
-                        EE_MIN_PHP_VER_REQUIRED,
84
-                        PHP_VERSION,
85
-                        '<br/>',
86
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
87
-                    );
88
-                    ?>
78
+					printf(
79
+						esc_html__(
80
+							'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.',
81
+							'event_espresso'
82
+						),
83
+						EE_MIN_PHP_VER_REQUIRED,
84
+						PHP_VERSION,
85
+						'<br/>',
86
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
87
+					);
88
+					?>
89 89
                 </p>
90 90
             </div>
91 91
             <?php
92
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
93
-        }
92
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
93
+		}
94 94
 
95
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
96
-    } else {
97
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
98
-        /**
99
-         * espresso_version
100
-         * Returns the plugin version
101
-         *
102
-         * @return string
103
-         */
104
-        function espresso_version()
105
-        {
106
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.50.rc.010');
107
-        }
95
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
96
+	} else {
97
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
98
+		/**
99
+		 * espresso_version
100
+		 * Returns the plugin version
101
+		 *
102
+		 * @return string
103
+		 */
104
+		function espresso_version()
105
+		{
106
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.50.rc.010');
107
+		}
108 108
 
109
-        /**
110
-         * espresso_plugin_activation
111
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
112
-         */
113
-        function espresso_plugin_activation()
114
-        {
115
-            update_option('ee_espresso_activation', true);
116
-        }
109
+		/**
110
+		 * espresso_plugin_activation
111
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
112
+		 */
113
+		function espresso_plugin_activation()
114
+		{
115
+			update_option('ee_espresso_activation', true);
116
+		}
117 117
 
118
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
119
-        /**
120
-         *    espresso_load_error_handling
121
-         *    this function loads EE's class for handling exceptions and errors
122
-         */
123
-        function espresso_load_error_handling()
124
-        {
125
-            static $error_handling_loaded = false;
126
-            if ($error_handling_loaded) {
127
-                return;
128
-            }
129
-            // load debugging tools
130
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
-                require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
132
-                \EEH_Debug_Tools::instance();
133
-            }
134
-            // load error handling
135
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
-                require_once EE_CORE . 'EE_Error.core.php';
137
-            } else {
138
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139
-            }
140
-            $error_handling_loaded = true;
141
-        }
118
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
119
+		/**
120
+		 *    espresso_load_error_handling
121
+		 *    this function loads EE's class for handling exceptions and errors
122
+		 */
123
+		function espresso_load_error_handling()
124
+		{
125
+			static $error_handling_loaded = false;
126
+			if ($error_handling_loaded) {
127
+				return;
128
+			}
129
+			// load debugging tools
130
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
+				require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
132
+				\EEH_Debug_Tools::instance();
133
+			}
134
+			// load error handling
135
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
+				require_once EE_CORE . 'EE_Error.core.php';
137
+			} else {
138
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139
+			}
140
+			$error_handling_loaded = true;
141
+		}
142 142
 
143
-        /**
144
-         *    espresso_load_required
145
-         *    given a class name and path, this function will load that file or throw an exception
146
-         *
147
-         * @param    string $classname
148
-         * @param    string $full_path_to_file
149
-         * @throws    EE_Error
150
-         */
151
-        function espresso_load_required($classname, $full_path_to_file)
152
-        {
153
-            if (is_readable($full_path_to_file)) {
154
-                require_once $full_path_to_file;
155
-            } else {
156
-                throw new \EE_Error (
157
-                    sprintf(
158
-                        esc_html__(
159
-                            'The %s class file could not be located or is not readable due to file permissions.',
160
-                            'event_espresso'
161
-                        ),
162
-                        $classname
163
-                    )
164
-                );
165
-            }
166
-        }
143
+		/**
144
+		 *    espresso_load_required
145
+		 *    given a class name and path, this function will load that file or throw an exception
146
+		 *
147
+		 * @param    string $classname
148
+		 * @param    string $full_path_to_file
149
+		 * @throws    EE_Error
150
+		 */
151
+		function espresso_load_required($classname, $full_path_to_file)
152
+		{
153
+			if (is_readable($full_path_to_file)) {
154
+				require_once $full_path_to_file;
155
+			} else {
156
+				throw new \EE_Error (
157
+					sprintf(
158
+						esc_html__(
159
+							'The %s class file could not be located or is not readable due to file permissions.',
160
+							'event_espresso'
161
+						),
162
+						$classname
163
+					)
164
+				);
165
+			}
166
+		}
167 167
 
168
-        /**
169
-         * @since 4.9.27
170
-         * @throws \EE_Error
171
-         * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
172
-         * @throws \EventEspresso\core\exceptions\InvalidEntityException
173
-         * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
174
-         * @throws \EventEspresso\core\exceptions\InvalidClassException
175
-         * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
176
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
177
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
178
-         * @throws \OutOfBoundsException
179
-         */
180
-        function bootstrap_espresso()
181
-        {
182
-            require_once __DIR__ . '/core/espresso_definitions.php';
183
-            try {
184
-                espresso_load_error_handling();
185
-                espresso_load_required(
186
-                    'EEH_Base',
187
-                    EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
188
-                );
189
-                espresso_load_required(
190
-                    'EEH_File',
191
-                    EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
192
-                );
193
-                espresso_load_required(
194
-                    'EEH_File',
195
-                    EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
196
-                );
197
-                espresso_load_required(
198
-                    'EEH_Array',
199
-                    EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
200
-                );
201
-                // instantiate and configure PSR4 autoloader
202
-                espresso_load_required(
203
-                    'Psr4Autoloader',
204
-                    EE_CORE . 'Psr4Autoloader.php'
205
-                );
206
-                espresso_load_required(
207
-                    'EE_Psr4AutoloaderInit',
208
-                    EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
209
-                );
210
-                $AutoloaderInit = new EE_Psr4AutoloaderInit();
211
-                $AutoloaderInit->initializeAutoloader();
212
-                espresso_load_required(
213
-                    'EE_Request',
214
-                    EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
215
-                );
216
-                espresso_load_required(
217
-                    'EE_Response',
218
-                    EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
219
-                );
220
-                espresso_load_required(
221
-                    'EE_Bootstrap',
222
-                    EE_CORE . 'EE_Bootstrap.core.php'
223
-                );
224
-                // bootstrap EE and the request stack
225
-                new EE_Bootstrap(
226
-                    new EE_Request($_GET, $_POST, $_COOKIE),
227
-                    new EE_Response()
228
-                );
229
-            } catch (Exception $e) {
230
-                require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
231
-                new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232
-            }
233
-        }
234
-        bootstrap_espresso();
235
-    }
168
+		/**
169
+		 * @since 4.9.27
170
+		 * @throws \EE_Error
171
+		 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
172
+		 * @throws \EventEspresso\core\exceptions\InvalidEntityException
173
+		 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
174
+		 * @throws \EventEspresso\core\exceptions\InvalidClassException
175
+		 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
176
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
177
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
178
+		 * @throws \OutOfBoundsException
179
+		 */
180
+		function bootstrap_espresso()
181
+		{
182
+			require_once __DIR__ . '/core/espresso_definitions.php';
183
+			try {
184
+				espresso_load_error_handling();
185
+				espresso_load_required(
186
+					'EEH_Base',
187
+					EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
188
+				);
189
+				espresso_load_required(
190
+					'EEH_File',
191
+					EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
192
+				);
193
+				espresso_load_required(
194
+					'EEH_File',
195
+					EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
196
+				);
197
+				espresso_load_required(
198
+					'EEH_Array',
199
+					EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
200
+				);
201
+				// instantiate and configure PSR4 autoloader
202
+				espresso_load_required(
203
+					'Psr4Autoloader',
204
+					EE_CORE . 'Psr4Autoloader.php'
205
+				);
206
+				espresso_load_required(
207
+					'EE_Psr4AutoloaderInit',
208
+					EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
209
+				);
210
+				$AutoloaderInit = new EE_Psr4AutoloaderInit();
211
+				$AutoloaderInit->initializeAutoloader();
212
+				espresso_load_required(
213
+					'EE_Request',
214
+					EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
215
+				);
216
+				espresso_load_required(
217
+					'EE_Response',
218
+					EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
219
+				);
220
+				espresso_load_required(
221
+					'EE_Bootstrap',
222
+					EE_CORE . 'EE_Bootstrap.core.php'
223
+				);
224
+				// bootstrap EE and the request stack
225
+				new EE_Bootstrap(
226
+					new EE_Request($_GET, $_POST, $_COOKIE),
227
+					new EE_Response()
228
+				);
229
+			} catch (Exception $e) {
230
+				require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
231
+				new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232
+			}
233
+		}
234
+		bootstrap_espresso();
235
+	}
236 236
 }
237 237
 if (! function_exists('espresso_deactivate_plugin')) {
238
-    /**
239
-     *    deactivate_plugin
240
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
241
-     *
242
-     * @access public
243
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
244
-     * @return    void
245
-     */
246
-    function espresso_deactivate_plugin($plugin_basename = '')
247
-    {
248
-        if (! function_exists('deactivate_plugins')) {
249
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
250
-        }
251
-        unset($_GET['activate'], $_REQUEST['activate']);
252
-        deactivate_plugins($plugin_basename);
253
-    }
238
+	/**
239
+	 *    deactivate_plugin
240
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
241
+	 *
242
+	 * @access public
243
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
244
+	 * @return    void
245
+	 */
246
+	function espresso_deactivate_plugin($plugin_basename = '')
247
+	{
248
+		if (! function_exists('deactivate_plugins')) {
249
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
250
+		}
251
+		unset($_GET['activate'], $_REQUEST['activate']);
252
+		deactivate_plugins($plugin_basename);
253
+	}
254 254
 }
Please login to merge, or discard this patch.