Completed
Branch FET/better-paypal-error-unauth... (0c8498)
by
unknown
34:21 queued 26:06
created
core/services/request/Request.php 1 patch
Indentation   +602 added lines, -602 removed lines patch added patch discarded remove patch
@@ -17,606 +17,606 @@
 block discarded – undo
17 17
 class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface
18 18
 {
19 19
 
20
-    /**
21
-     * $_GET parameters
22
-     *
23
-     * @var array $get
24
-     */
25
-    private $get;
26
-
27
-    /**
28
-     * $_POST parameters
29
-     *
30
-     * @var array $post
31
-     */
32
-    private $post;
33
-
34
-    /**
35
-     * $_COOKIE parameters
36
-     *
37
-     * @var array $cookie
38
-     */
39
-    private $cookie;
40
-
41
-    /**
42
-     * $_SERVER parameters
43
-     *
44
-     * @var array $server
45
-     */
46
-    private $server;
47
-
48
-    /**
49
-     * $_REQUEST parameters
50
-     *
51
-     * @var array $request
52
-     */
53
-    private $request;
54
-
55
-    /**
56
-     * @var RequestTypeContextCheckerInterface
57
-     */
58
-    private $request_type;
59
-
60
-    /**
61
-     * IP address for request
62
-     *
63
-     * @var string $ip_address
64
-     */
65
-    private $ip_address;
66
-
67
-    /**
68
-     * @var string $user_agent
69
-     */
70
-    private $user_agent;
71
-
72
-    /**
73
-     * true if current user appears to be some kind of bot
74
-     *
75
-     * @var bool $is_bot
76
-     */
77
-    private $is_bot;
78
-
79
-
80
-    /**
81
-     * @param array $get
82
-     * @param array $post
83
-     * @param array $cookie
84
-     * @param array $server
85
-     */
86
-    public function __construct(array $get, array $post, array $cookie, array $server)
87
-    {
88
-        // grab request vars
89
-        $this->get = $get;
90
-        $this->post = $post;
91
-        $this->cookie = $cookie;
92
-        $this->server = $server;
93
-        $this->request = array_merge($this->get, $this->post);
94
-        $this->ip_address = $this->visitorIp();
95
-    }
96
-
97
-
98
-    /**
99
-     * @param RequestTypeContextCheckerInterface $type
100
-     */
101
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
102
-    {
103
-        $this->request_type = $type;
104
-    }
105
-
106
-
107
-    /**
108
-     * @return array
109
-     */
110
-    public function getParams()
111
-    {
112
-        return $this->get;
113
-    }
114
-
115
-
116
-    /**
117
-     * @return array
118
-     */
119
-    public function postParams()
120
-    {
121
-        return $this->post;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return array
127
-     */
128
-    public function cookieParams()
129
-    {
130
-        return $this->cookie;
131
-    }
132
-
133
-
134
-    /**
135
-     * @return array
136
-     */
137
-    public function serverParams()
138
-    {
139
-        return $this->server;
140
-    }
141
-
142
-
143
-    /**
144
-     * returns contents of $_REQUEST
145
-     *
146
-     * @return array
147
-     */
148
-    public function requestParams()
149
-    {
150
-        return $this->request;
151
-    }
152
-
153
-
154
-    /**
155
-     * @param      $key
156
-     * @param      $value
157
-     * @param bool $override_ee
158
-     * @return    void
159
-     */
160
-    public function setRequestParam($key, $value, $override_ee = false)
161
-    {
162
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
163
-        if ($key !== 'ee'
164
-            || ($key === 'ee' && empty($this->request['ee']))
165
-            || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
166
-        ) {
167
-            $this->request[ $key ] = $value;
168
-        }
169
-    }
170
-
171
-
172
-    /**
173
-     * returns   the value for a request param if the given key exists
174
-     *
175
-     * @param       $key
176
-     * @param null  $default
177
-     * @return mixed
178
-     */
179
-    public function getRequestParam($key, $default = null)
180
-    {
181
-        return $this->requestParameterDrillDown($key, $default, 'get');
182
-    }
183
-
184
-
185
-    /**
186
-     * check if param exists
187
-     *
188
-     * @param       $key
189
-     * @return bool
190
-     */
191
-    public function requestParamIsSet($key)
192
-    {
193
-        return $this->requestParameterDrillDown($key);
194
-    }
195
-
196
-
197
-    /**
198
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
199
-     * and return the value for the first match found
200
-     * wildcards can be either of the following:
201
-     *      ? to represent a single character of any type
202
-     *      * to represent one or more characters of any type
203
-     *
204
-     * @param string     $pattern
205
-     * @param null|mixed $default
206
-     * @return mixed
207
-     */
208
-    public function getMatch($pattern, $default = null)
209
-    {
210
-        return $this->requestParameterDrillDown($pattern, $default, 'match');
211
-    }
212
-
213
-
214
-    /**
215
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
216
-     * wildcards can be either of the following:
217
-     *      ? to represent a single character of any type
218
-     *      * to represent one or more characters of any type
219
-     * returns true if a match is found or false if not
220
-     *
221
-     * @param string $pattern
222
-     * @return bool
223
-     */
224
-    public function matches($pattern)
225
-    {
226
-        return $this->requestParameterDrillDown($pattern, null, 'match') !== null;
227
-    }
228
-
229
-
230
-    /**
231
-     * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
232
-     * @param string $pattern               A string including wildcards to be converted to a regex pattern
233
-     *                                      and used to search through the current request's parameter keys
234
-     * @param array  $request_params        The array of request parameters to search through
235
-     * @param mixed  $default               [optional] The value to be returned if no match is found.
236
-     *                                      Default is null
237
-     * @param string $return                [optional] Controls what kind of value is returned.
238
-     *                                      Options are:
239
-     *                                      'bool' will return true or false if match is found or not
240
-     *                                      'key' will return the first key found that matches the supplied pattern
241
-     *                                      'value' will return the value for the first request parameter
242
-     *                                      whose key matches the supplied pattern
243
-     *                                      Default is 'value'
244
-     * @return boolean|string
245
-     */
246
-    private function match($pattern, array $request_params, $default = null, $return = 'value')
247
-    {
248
-        $return = in_array($return, array('bool', 'key', 'value'), true)
249
-            ? $return
250
-            : 'is_set';
251
-        // replace wildcard chars with regex chars
252
-        $pattern = str_replace(
253
-            array("\*", "\?"),
254
-            array('.*', '.'),
255
-            preg_quote($pattern, '/')
256
-        );
257
-        foreach ($request_params as $key => $request_param) {
258
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
259
-                // return value for request param
260
-                if ($return === 'value') {
261
-                    return $request_params[ $key ];
262
-                }
263
-                // or actual key or true just to indicate it was found
264
-                return $return === 'key' ? $key : true;
265
-            }
266
-        }
267
-        // match not found so return default value or false
268
-        return $return === 'value' ? $default : false;
269
-    }
270
-
271
-
272
-    /**
273
-     * the supplied key can be a simple string to represent a "top-level" request parameter
274
-     * or represent a key for a request parameter that is nested deeper within the request parameter array,
275
-     * by using square brackets to surround keys for deeper array elements.
276
-     * For example :
277
-     * if the supplied $key was: "first[second][third]"
278
-     * then this will attempt to drill down into the request parameter array to find a value.
279
-     * Given the following request parameters:
280
-     *  array(
281
-     *      'first' => array(
282
-     *          'second' => array(
283
-     *              'third' => 'has a value'
284
-     *          )
285
-     *      )
286
-     *  )
287
-     * would return true if default parameters were set
288
-     *
289
-     * @param string $callback
290
-     * @param        $key
291
-     * @param null   $default
292
-     * @param array  $request_params
293
-     * @return bool|mixed|null
294
-     */
295
-    private function requestParameterDrillDown(
296
-        $key,
297
-        $default = null,
298
-        $callback = 'is_set',
299
-        array $request_params = array()
300
-    ) {
301
-        $callback = in_array($callback, array('is_set', 'get', 'match'), true)
302
-            ? $callback
303
-            : 'is_set';
304
-        $request_params = ! empty($request_params)
305
-            ? $request_params
306
-            : $this->request;
307
-        // does incoming key represent an array like 'first[second][third]'  ?
308
-        if (strpos($key, '[') !== false) {
309
-            // turn it into an actual array
310
-            $key = str_replace(']', '', $key);
311
-            $keys = explode('[', $key);
312
-            $key = array_shift($keys);
313
-            if ($callback === 'match') {
314
-                $real_key = $this->match($key, $request_params, $default, 'key');
315
-                $key = $real_key ? $real_key : $key;
316
-            }
317
-            // check if top level key exists
318
-            if (isset($request_params[ $key ])) {
319
-                // build a new key to pass along like: 'second[third]'
320
-                // or just 'second' depending on depth of keys
321
-                $key_string = array_shift($keys);
322
-                if (! empty($keys)) {
323
-                    $key_string .= '[' . implode('][', $keys) . ']';
324
-                }
325
-                return $this->requestParameterDrillDown(
326
-                    $key_string,
327
-                    $default,
328
-                    $callback,
329
-                    $request_params[ $key ]
330
-                );
331
-            }
332
-        }
333
-        if ($callback === 'is_set') {
334
-            return isset($request_params[ $key ]);
335
-        }
336
-        if ($callback === 'match') {
337
-            return $this->match($key, $request_params, $default);
338
-        }
339
-        return isset($request_params[ $key ])
340
-            ? $request_params[ $key ]
341
-            : $default;
342
-    }
343
-
344
-
345
-    /**
346
-     * remove param
347
-     *
348
-     * @param      $key
349
-     * @param bool $unset_from_global_too
350
-     */
351
-    public function unSetRequestParam($key, $unset_from_global_too = false)
352
-    {
353
-        unset($this->request[ $key ]);
354
-        if ($unset_from_global_too) {
355
-            unset($_REQUEST[ $key ]);
356
-        }
357
-    }
358
-
359
-
360
-    /**
361
-     * @return string
362
-     */
363
-    public function ipAddress()
364
-    {
365
-        return $this->ip_address;
366
-    }
367
-
368
-
369
-    /**
370
-     * attempt to get IP address of current visitor from server
371
-     * plz see: http://stackoverflow.com/a/2031935/1475279
372
-     *
373
-     * @access public
374
-     * @return string
375
-     */
376
-    private function visitorIp()
377
-    {
378
-        $visitor_ip = '0.0.0.0';
379
-        $server_keys = array(
380
-            'HTTP_CLIENT_IP',
381
-            'HTTP_X_FORWARDED_FOR',
382
-            'HTTP_X_FORWARDED',
383
-            'HTTP_X_CLUSTER_CLIENT_IP',
384
-            'HTTP_FORWARDED_FOR',
385
-            'HTTP_FORWARDED',
386
-            'REMOTE_ADDR',
387
-        );
388
-        foreach ($server_keys as $key) {
389
-            if (isset($this->server[ $key ])) {
390
-                foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
391
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
392
-                        $visitor_ip = $ip;
393
-                    }
394
-                }
395
-            }
396
-        }
397
-        return $visitor_ip;
398
-    }
399
-
400
-
401
-    /**
402
-     * @return string
403
-     */
404
-    public function requestUri()
405
-    {
406
-        $request_uri = filter_input(
407
-            INPUT_SERVER,
408
-            'REQUEST_URI',
409
-            FILTER_SANITIZE_URL,
410
-            FILTER_NULL_ON_FAILURE
411
-        );
412
-        if (empty($request_uri)) {
413
-            // fallback sanitization if the above fails
414
-            $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
415
-        }
416
-        return $request_uri;
417
-    }
418
-
419
-
420
-    /**
421
-     * @return string
422
-     */
423
-    public function userAgent()
424
-    {
425
-        return $this->user_agent;
426
-    }
427
-
428
-
429
-    /**
430
-     * @param string $user_agent
431
-     */
432
-    public function setUserAgent($user_agent = '')
433
-    {
434
-        if ($user_agent === '' || ! is_string($user_agent)) {
435
-            $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
436
-        }
437
-        $this->user_agent = $user_agent;
438
-    }
439
-
440
-
441
-    /**
442
-     * @return bool
443
-     */
444
-    public function isBot()
445
-    {
446
-        return $this->is_bot;
447
-    }
448
-
449
-
450
-    /**
451
-     * @param bool $is_bot
452
-     */
453
-    public function setIsBot($is_bot)
454
-    {
455
-        $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
456
-    }
457
-
458
-
459
-    /**
460
-     * @return bool
461
-     */
462
-    public function isActivation()
463
-    {
464
-        return $this->request_type->isActivation();
465
-    }
466
-
467
-
468
-    /**
469
-     * @param $is_activation
470
-     * @return bool
471
-     */
472
-    public function setIsActivation($is_activation)
473
-    {
474
-        return $this->request_type->setIsActivation($is_activation);
475
-    }
476
-
477
-
478
-    /**
479
-     * @return bool
480
-     */
481
-    public function isAdmin()
482
-    {
483
-        return $this->request_type->isAdmin();
484
-    }
485
-
486
-
487
-    /**
488
-     * @return bool
489
-     */
490
-    public function isAdminAjax()
491
-    {
492
-        return $this->request_type->isAdminAjax();
493
-    }
494
-
495
-
496
-    /**
497
-     * @return bool
498
-     */
499
-    public function isAjax()
500
-    {
501
-        return $this->request_type->isAjax();
502
-    }
503
-
504
-
505
-    /**
506
-     * @return bool
507
-     */
508
-    public function isEeAjax()
509
-    {
510
-        return $this->request_type->isEeAjax();
511
-    }
512
-
513
-
514
-    /**
515
-     * @return bool
516
-     */
517
-    public function isOtherAjax()
518
-    {
519
-        return $this->request_type->isOtherAjax();
520
-    }
521
-
522
-
523
-    /**
524
-     * @return bool
525
-     */
526
-    public function isApi()
527
-    {
528
-        return $this->request_type->isApi();
529
-    }
530
-
531
-
532
-    /**
533
-     * @return bool
534
-     */
535
-    public function isCli()
536
-    {
537
-        return $this->request_type->isCli();
538
-    }
539
-
540
-
541
-    /**
542
-     * @return bool
543
-     */
544
-    public function isCron()
545
-    {
546
-        return $this->request_type->isCron();
547
-    }
548
-
549
-
550
-    /**
551
-     * @return bool
552
-     */
553
-    public function isFeed()
554
-    {
555
-        return $this->request_type->isFeed();
556
-    }
557
-
558
-
559
-    /**
560
-     * @return bool
561
-     */
562
-    public function isFrontend()
563
-    {
564
-        return $this->request_type->isFrontend();
565
-    }
566
-
567
-
568
-    /**
569
-     * @return bool
570
-     */
571
-    public function isFrontAjax()
572
-    {
573
-        return $this->request_type->isFrontAjax();
574
-    }
575
-
576
-
577
-    /**
578
-     * @return bool
579
-     */
580
-    public function isIframe()
581
-    {
582
-        return $this->request_type->isIframe();
583
-    }
584
-
585
-
586
-    /**
587
-     * @return bool
588
-     */
589
-    public function isWordPressApi()
590
-    {
591
-        return $this->request_type->isWordPressApi();
592
-    }
593
-
594
-
595
-
596
-    /**
597
-     * @return bool
598
-     */
599
-    public function isWordPressHeartbeat()
600
-    {
601
-        return $this->request_type->isWordPressHeartbeat();
602
-    }
603
-
604
-
605
-
606
-    /**
607
-     * @return bool
608
-     */
609
-    public function isWordPressScrape()
610
-    {
611
-        return $this->request_type->isWordPressScrape();
612
-    }
613
-
614
-
615
-    /**
616
-     * @return string
617
-     */
618
-    public function slug()
619
-    {
620
-        return $this->request_type->slug();
621
-    }
20
+	/**
21
+	 * $_GET parameters
22
+	 *
23
+	 * @var array $get
24
+	 */
25
+	private $get;
26
+
27
+	/**
28
+	 * $_POST parameters
29
+	 *
30
+	 * @var array $post
31
+	 */
32
+	private $post;
33
+
34
+	/**
35
+	 * $_COOKIE parameters
36
+	 *
37
+	 * @var array $cookie
38
+	 */
39
+	private $cookie;
40
+
41
+	/**
42
+	 * $_SERVER parameters
43
+	 *
44
+	 * @var array $server
45
+	 */
46
+	private $server;
47
+
48
+	/**
49
+	 * $_REQUEST parameters
50
+	 *
51
+	 * @var array $request
52
+	 */
53
+	private $request;
54
+
55
+	/**
56
+	 * @var RequestTypeContextCheckerInterface
57
+	 */
58
+	private $request_type;
59
+
60
+	/**
61
+	 * IP address for request
62
+	 *
63
+	 * @var string $ip_address
64
+	 */
65
+	private $ip_address;
66
+
67
+	/**
68
+	 * @var string $user_agent
69
+	 */
70
+	private $user_agent;
71
+
72
+	/**
73
+	 * true if current user appears to be some kind of bot
74
+	 *
75
+	 * @var bool $is_bot
76
+	 */
77
+	private $is_bot;
78
+
79
+
80
+	/**
81
+	 * @param array $get
82
+	 * @param array $post
83
+	 * @param array $cookie
84
+	 * @param array $server
85
+	 */
86
+	public function __construct(array $get, array $post, array $cookie, array $server)
87
+	{
88
+		// grab request vars
89
+		$this->get = $get;
90
+		$this->post = $post;
91
+		$this->cookie = $cookie;
92
+		$this->server = $server;
93
+		$this->request = array_merge($this->get, $this->post);
94
+		$this->ip_address = $this->visitorIp();
95
+	}
96
+
97
+
98
+	/**
99
+	 * @param RequestTypeContextCheckerInterface $type
100
+	 */
101
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
102
+	{
103
+		$this->request_type = $type;
104
+	}
105
+
106
+
107
+	/**
108
+	 * @return array
109
+	 */
110
+	public function getParams()
111
+	{
112
+		return $this->get;
113
+	}
114
+
115
+
116
+	/**
117
+	 * @return array
118
+	 */
119
+	public function postParams()
120
+	{
121
+		return $this->post;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return array
127
+	 */
128
+	public function cookieParams()
129
+	{
130
+		return $this->cookie;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return array
136
+	 */
137
+	public function serverParams()
138
+	{
139
+		return $this->server;
140
+	}
141
+
142
+
143
+	/**
144
+	 * returns contents of $_REQUEST
145
+	 *
146
+	 * @return array
147
+	 */
148
+	public function requestParams()
149
+	{
150
+		return $this->request;
151
+	}
152
+
153
+
154
+	/**
155
+	 * @param      $key
156
+	 * @param      $value
157
+	 * @param bool $override_ee
158
+	 * @return    void
159
+	 */
160
+	public function setRequestParam($key, $value, $override_ee = false)
161
+	{
162
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
163
+		if ($key !== 'ee'
164
+			|| ($key === 'ee' && empty($this->request['ee']))
165
+			|| ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
166
+		) {
167
+			$this->request[ $key ] = $value;
168
+		}
169
+	}
170
+
171
+
172
+	/**
173
+	 * returns   the value for a request param if the given key exists
174
+	 *
175
+	 * @param       $key
176
+	 * @param null  $default
177
+	 * @return mixed
178
+	 */
179
+	public function getRequestParam($key, $default = null)
180
+	{
181
+		return $this->requestParameterDrillDown($key, $default, 'get');
182
+	}
183
+
184
+
185
+	/**
186
+	 * check if param exists
187
+	 *
188
+	 * @param       $key
189
+	 * @return bool
190
+	 */
191
+	public function requestParamIsSet($key)
192
+	{
193
+		return $this->requestParameterDrillDown($key);
194
+	}
195
+
196
+
197
+	/**
198
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
199
+	 * and return the value for the first match found
200
+	 * wildcards can be either of the following:
201
+	 *      ? to represent a single character of any type
202
+	 *      * to represent one or more characters of any type
203
+	 *
204
+	 * @param string     $pattern
205
+	 * @param null|mixed $default
206
+	 * @return mixed
207
+	 */
208
+	public function getMatch($pattern, $default = null)
209
+	{
210
+		return $this->requestParameterDrillDown($pattern, $default, 'match');
211
+	}
212
+
213
+
214
+	/**
215
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
216
+	 * wildcards can be either of the following:
217
+	 *      ? to represent a single character of any type
218
+	 *      * to represent one or more characters of any type
219
+	 * returns true if a match is found or false if not
220
+	 *
221
+	 * @param string $pattern
222
+	 * @return bool
223
+	 */
224
+	public function matches($pattern)
225
+	{
226
+		return $this->requestParameterDrillDown($pattern, null, 'match') !== null;
227
+	}
228
+
229
+
230
+	/**
231
+	 * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
232
+	 * @param string $pattern               A string including wildcards to be converted to a regex pattern
233
+	 *                                      and used to search through the current request's parameter keys
234
+	 * @param array  $request_params        The array of request parameters to search through
235
+	 * @param mixed  $default               [optional] The value to be returned if no match is found.
236
+	 *                                      Default is null
237
+	 * @param string $return                [optional] Controls what kind of value is returned.
238
+	 *                                      Options are:
239
+	 *                                      'bool' will return true or false if match is found or not
240
+	 *                                      'key' will return the first key found that matches the supplied pattern
241
+	 *                                      'value' will return the value for the first request parameter
242
+	 *                                      whose key matches the supplied pattern
243
+	 *                                      Default is 'value'
244
+	 * @return boolean|string
245
+	 */
246
+	private function match($pattern, array $request_params, $default = null, $return = 'value')
247
+	{
248
+		$return = in_array($return, array('bool', 'key', 'value'), true)
249
+			? $return
250
+			: 'is_set';
251
+		// replace wildcard chars with regex chars
252
+		$pattern = str_replace(
253
+			array("\*", "\?"),
254
+			array('.*', '.'),
255
+			preg_quote($pattern, '/')
256
+		);
257
+		foreach ($request_params as $key => $request_param) {
258
+			if (preg_match('/^' . $pattern . '$/is', $key)) {
259
+				// return value for request param
260
+				if ($return === 'value') {
261
+					return $request_params[ $key ];
262
+				}
263
+				// or actual key or true just to indicate it was found
264
+				return $return === 'key' ? $key : true;
265
+			}
266
+		}
267
+		// match not found so return default value or false
268
+		return $return === 'value' ? $default : false;
269
+	}
270
+
271
+
272
+	/**
273
+	 * the supplied key can be a simple string to represent a "top-level" request parameter
274
+	 * or represent a key for a request parameter that is nested deeper within the request parameter array,
275
+	 * by using square brackets to surround keys for deeper array elements.
276
+	 * For example :
277
+	 * if the supplied $key was: "first[second][third]"
278
+	 * then this will attempt to drill down into the request parameter array to find a value.
279
+	 * Given the following request parameters:
280
+	 *  array(
281
+	 *      'first' => array(
282
+	 *          'second' => array(
283
+	 *              'third' => 'has a value'
284
+	 *          )
285
+	 *      )
286
+	 *  )
287
+	 * would return true if default parameters were set
288
+	 *
289
+	 * @param string $callback
290
+	 * @param        $key
291
+	 * @param null   $default
292
+	 * @param array  $request_params
293
+	 * @return bool|mixed|null
294
+	 */
295
+	private function requestParameterDrillDown(
296
+		$key,
297
+		$default = null,
298
+		$callback = 'is_set',
299
+		array $request_params = array()
300
+	) {
301
+		$callback = in_array($callback, array('is_set', 'get', 'match'), true)
302
+			? $callback
303
+			: 'is_set';
304
+		$request_params = ! empty($request_params)
305
+			? $request_params
306
+			: $this->request;
307
+		// does incoming key represent an array like 'first[second][third]'  ?
308
+		if (strpos($key, '[') !== false) {
309
+			// turn it into an actual array
310
+			$key = str_replace(']', '', $key);
311
+			$keys = explode('[', $key);
312
+			$key = array_shift($keys);
313
+			if ($callback === 'match') {
314
+				$real_key = $this->match($key, $request_params, $default, 'key');
315
+				$key = $real_key ? $real_key : $key;
316
+			}
317
+			// check if top level key exists
318
+			if (isset($request_params[ $key ])) {
319
+				// build a new key to pass along like: 'second[third]'
320
+				// or just 'second' depending on depth of keys
321
+				$key_string = array_shift($keys);
322
+				if (! empty($keys)) {
323
+					$key_string .= '[' . implode('][', $keys) . ']';
324
+				}
325
+				return $this->requestParameterDrillDown(
326
+					$key_string,
327
+					$default,
328
+					$callback,
329
+					$request_params[ $key ]
330
+				);
331
+			}
332
+		}
333
+		if ($callback === 'is_set') {
334
+			return isset($request_params[ $key ]);
335
+		}
336
+		if ($callback === 'match') {
337
+			return $this->match($key, $request_params, $default);
338
+		}
339
+		return isset($request_params[ $key ])
340
+			? $request_params[ $key ]
341
+			: $default;
342
+	}
343
+
344
+
345
+	/**
346
+	 * remove param
347
+	 *
348
+	 * @param      $key
349
+	 * @param bool $unset_from_global_too
350
+	 */
351
+	public function unSetRequestParam($key, $unset_from_global_too = false)
352
+	{
353
+		unset($this->request[ $key ]);
354
+		if ($unset_from_global_too) {
355
+			unset($_REQUEST[ $key ]);
356
+		}
357
+	}
358
+
359
+
360
+	/**
361
+	 * @return string
362
+	 */
363
+	public function ipAddress()
364
+	{
365
+		return $this->ip_address;
366
+	}
367
+
368
+
369
+	/**
370
+	 * attempt to get IP address of current visitor from server
371
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
372
+	 *
373
+	 * @access public
374
+	 * @return string
375
+	 */
376
+	private function visitorIp()
377
+	{
378
+		$visitor_ip = '0.0.0.0';
379
+		$server_keys = array(
380
+			'HTTP_CLIENT_IP',
381
+			'HTTP_X_FORWARDED_FOR',
382
+			'HTTP_X_FORWARDED',
383
+			'HTTP_X_CLUSTER_CLIENT_IP',
384
+			'HTTP_FORWARDED_FOR',
385
+			'HTTP_FORWARDED',
386
+			'REMOTE_ADDR',
387
+		);
388
+		foreach ($server_keys as $key) {
389
+			if (isset($this->server[ $key ])) {
390
+				foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
391
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
392
+						$visitor_ip = $ip;
393
+					}
394
+				}
395
+			}
396
+		}
397
+		return $visitor_ip;
398
+	}
399
+
400
+
401
+	/**
402
+	 * @return string
403
+	 */
404
+	public function requestUri()
405
+	{
406
+		$request_uri = filter_input(
407
+			INPUT_SERVER,
408
+			'REQUEST_URI',
409
+			FILTER_SANITIZE_URL,
410
+			FILTER_NULL_ON_FAILURE
411
+		);
412
+		if (empty($request_uri)) {
413
+			// fallback sanitization if the above fails
414
+			$request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
415
+		}
416
+		return $request_uri;
417
+	}
418
+
419
+
420
+	/**
421
+	 * @return string
422
+	 */
423
+	public function userAgent()
424
+	{
425
+		return $this->user_agent;
426
+	}
427
+
428
+
429
+	/**
430
+	 * @param string $user_agent
431
+	 */
432
+	public function setUserAgent($user_agent = '')
433
+	{
434
+		if ($user_agent === '' || ! is_string($user_agent)) {
435
+			$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
436
+		}
437
+		$this->user_agent = $user_agent;
438
+	}
439
+
440
+
441
+	/**
442
+	 * @return bool
443
+	 */
444
+	public function isBot()
445
+	{
446
+		return $this->is_bot;
447
+	}
448
+
449
+
450
+	/**
451
+	 * @param bool $is_bot
452
+	 */
453
+	public function setIsBot($is_bot)
454
+	{
455
+		$this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
456
+	}
457
+
458
+
459
+	/**
460
+	 * @return bool
461
+	 */
462
+	public function isActivation()
463
+	{
464
+		return $this->request_type->isActivation();
465
+	}
466
+
467
+
468
+	/**
469
+	 * @param $is_activation
470
+	 * @return bool
471
+	 */
472
+	public function setIsActivation($is_activation)
473
+	{
474
+		return $this->request_type->setIsActivation($is_activation);
475
+	}
476
+
477
+
478
+	/**
479
+	 * @return bool
480
+	 */
481
+	public function isAdmin()
482
+	{
483
+		return $this->request_type->isAdmin();
484
+	}
485
+
486
+
487
+	/**
488
+	 * @return bool
489
+	 */
490
+	public function isAdminAjax()
491
+	{
492
+		return $this->request_type->isAdminAjax();
493
+	}
494
+
495
+
496
+	/**
497
+	 * @return bool
498
+	 */
499
+	public function isAjax()
500
+	{
501
+		return $this->request_type->isAjax();
502
+	}
503
+
504
+
505
+	/**
506
+	 * @return bool
507
+	 */
508
+	public function isEeAjax()
509
+	{
510
+		return $this->request_type->isEeAjax();
511
+	}
512
+
513
+
514
+	/**
515
+	 * @return bool
516
+	 */
517
+	public function isOtherAjax()
518
+	{
519
+		return $this->request_type->isOtherAjax();
520
+	}
521
+
522
+
523
+	/**
524
+	 * @return bool
525
+	 */
526
+	public function isApi()
527
+	{
528
+		return $this->request_type->isApi();
529
+	}
530
+
531
+
532
+	/**
533
+	 * @return bool
534
+	 */
535
+	public function isCli()
536
+	{
537
+		return $this->request_type->isCli();
538
+	}
539
+
540
+
541
+	/**
542
+	 * @return bool
543
+	 */
544
+	public function isCron()
545
+	{
546
+		return $this->request_type->isCron();
547
+	}
548
+
549
+
550
+	/**
551
+	 * @return bool
552
+	 */
553
+	public function isFeed()
554
+	{
555
+		return $this->request_type->isFeed();
556
+	}
557
+
558
+
559
+	/**
560
+	 * @return bool
561
+	 */
562
+	public function isFrontend()
563
+	{
564
+		return $this->request_type->isFrontend();
565
+	}
566
+
567
+
568
+	/**
569
+	 * @return bool
570
+	 */
571
+	public function isFrontAjax()
572
+	{
573
+		return $this->request_type->isFrontAjax();
574
+	}
575
+
576
+
577
+	/**
578
+	 * @return bool
579
+	 */
580
+	public function isIframe()
581
+	{
582
+		return $this->request_type->isIframe();
583
+	}
584
+
585
+
586
+	/**
587
+	 * @return bool
588
+	 */
589
+	public function isWordPressApi()
590
+	{
591
+		return $this->request_type->isWordPressApi();
592
+	}
593
+
594
+
595
+
596
+	/**
597
+	 * @return bool
598
+	 */
599
+	public function isWordPressHeartbeat()
600
+	{
601
+		return $this->request_type->isWordPressHeartbeat();
602
+	}
603
+
604
+
605
+
606
+	/**
607
+	 * @return bool
608
+	 */
609
+	public function isWordPressScrape()
610
+	{
611
+		return $this->request_type->isWordPressScrape();
612
+	}
613
+
614
+
615
+	/**
616
+	 * @return string
617
+	 */
618
+	public function slug()
619
+	{
620
+		return $this->request_type->slug();
621
+	}
622 622
 }
Please login to merge, or discard this patch.
core/domain/services/admin/ajax/WordpressHeartbeat.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -17,50 +17,50 @@
 block discarded – undo
17 17
 class WordpressHeartbeat
18 18
 {
19 19
 
20
-    /**
21
-     * @var LoaderInterface $loader
22
-     */
23
-    protected $loader;
20
+	/**
21
+	 * @var LoaderInterface $loader
22
+	 */
23
+	protected $loader;
24 24
 
25
-    /**
26
-     * @var RequestInterface $request
27
-     */
28
-    protected $request;
25
+	/**
26
+	 * @var RequestInterface $request
27
+	 */
28
+	protected $request;
29 29
 
30 30
 
31
-    /**
32
-     * WordpressHeartbeat constructor.
33
-     *
34
-     * @param LoaderInterface  $loader
35
-     * @param RequestInterface $request
36
-     */
37
-    public function __construct(
38
-        LoaderInterface $loader,
39
-        RequestInterface $request
40
-    ) {
41
-        $this->loader = $loader;
42
-        $this->request = $request;
43
-        do_action('AHEE__EventEspresso_core_domain_services_admin_ajax_WordpressHeartbeat__constructor', $this);
44
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'resolveRoutes'));
45
-    }
31
+	/**
32
+	 * WordpressHeartbeat constructor.
33
+	 *
34
+	 * @param LoaderInterface  $loader
35
+	 * @param RequestInterface $request
36
+	 */
37
+	public function __construct(
38
+		LoaderInterface $loader,
39
+		RequestInterface $request
40
+	) {
41
+		$this->loader = $loader;
42
+		$this->request = $request;
43
+		do_action('AHEE__EventEspresso_core_domain_services_admin_ajax_WordpressHeartbeat__constructor', $this);
44
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'resolveRoutes'));
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * @since $VID:$
50
-     * @throws InvalidClassException
51
-     */
52
-    public function resolveRoutes()
53
-    {
54
-        $screenID = $this->request->getRequestParam('screen_id');
55
-        $heartbeat_data = $this->request->getRequestParam('data', []);
56
-        if ($screenID === 'espresso_events') {
57
-            $this->loader->getShared(
58
-                'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat'
59
-            );
60
-        } elseif ($screenID === 'front' && ! empty($heartbeat_data['espresso_thank_you_page'])) {
61
-            $this->loader->getShared(
62
-                'EventEspresso\core\domain\services\admin\ajax\ThankYouPageIpnMonitor'
63
-            );
64
-        }
65
-    }
48
+	/**
49
+	 * @since $VID:$
50
+	 * @throws InvalidClassException
51
+	 */
52
+	public function resolveRoutes()
53
+	{
54
+		$screenID = $this->request->getRequestParam('screen_id');
55
+		$heartbeat_data = $this->request->getRequestParam('data', []);
56
+		if ($screenID === 'espresso_events') {
57
+			$this->loader->getShared(
58
+				'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat'
59
+			);
60
+		} elseif ($screenID === 'front' && ! empty($heartbeat_data['espresso_thank_you_page'])) {
61
+			$this->loader->getShared(
62
+				'EventEspresso\core\domain\services\admin\ajax\ThankYouPageIpnMonitor'
63
+			);
64
+		}
65
+	}
66 66
 }
Please login to merge, or discard this patch.
core/domain/services/admin/ajax/EventEditorHeartbeat.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -16,52 +16,52 @@
 block discarded – undo
16 16
 class EventEditorHeartbeat
17 17
 {
18 18
 
19
-    /**
20
-     * @var Domain $domain
21
-     */
22
-    protected $domain;
19
+	/**
20
+	 * @var Domain $domain
21
+	 */
22
+	protected $domain;
23 23
 
24
-    /**
25
-     * @var EE_Environment_Config $environment
26
-     */
27
-    protected $environment;
24
+	/**
25
+	 * @var EE_Environment_Config $environment
26
+	 */
27
+	protected $environment;
28 28
 
29 29
 
30
-    /**
31
-     * EventEditorHeartbeat constructor.
32
-     *
33
-     * @param Domain                $domain
34
-     * @param EE_Environment_Config $environment
35
-     */
36
-    public function __construct(Domain $domain, EE_Environment_Config $environment)
37
-    {
38
-        $this->domain = $domain;
39
-        $this->environment = $environment;
40
-        if ($this->domain->isCaffeinated()) {
41
-            add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 2);
42
-        }
43
-    }
30
+	/**
31
+	 * EventEditorHeartbeat constructor.
32
+	 *
33
+	 * @param Domain                $domain
34
+	 * @param EE_Environment_Config $environment
35
+	 */
36
+	public function __construct(Domain $domain, EE_Environment_Config $environment)
37
+	{
38
+		$this->domain = $domain;
39
+		$this->environment = $environment;
40
+		if ($this->domain->isCaffeinated()) {
41
+			add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 2);
42
+		}
43
+	}
44 44
 
45 45
 
46
-    /**
47
-     * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
48
-     * accordingly.
49
-     *
50
-     * @param array $response The existing heartbeat response array.
51
-     * @param array $data     The incoming data package.
52
-     * @return array  possibly appended response.
53
-     */
54
-    public function heartbeatResponse($response, $data)
55
-    {
56
-        /**
57
-         * check whether count of tickets is approaching the potential
58
-         * limits for the server.
59
-         */
60
-        if (! empty($data['input_count'])) {
61
-            $response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check(
62
-                $data['input_count']
63
-            );
64
-        }
65
-        return $response;
66
-    }
46
+	/**
47
+	 * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
48
+	 * accordingly.
49
+	 *
50
+	 * @param array $response The existing heartbeat response array.
51
+	 * @param array $data     The incoming data package.
52
+	 * @return array  possibly appended response.
53
+	 */
54
+	public function heartbeatResponse($response, $data)
55
+	{
56
+		/**
57
+		 * check whether count of tickets is approaching the potential
58
+		 * limits for the server.
59
+		 */
60
+		if (! empty($data['input_count'])) {
61
+			$response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check(
62
+				$data['input_count']
63
+			);
64
+		}
65
+		return $response;
66
+	}
67 67
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
57 57
          * check whether count of tickets is approaching the potential
58 58
          * limits for the server.
59 59
          */
60
-        if (! empty($data['input_count'])) {
60
+        if ( ! empty($data['input_count'])) {
61 61
             $response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check(
62 62
                 $data['input_count']
63 63
             );
Please login to merge, or discard this patch.
core/domain/services/admin/ajax/ThankYouPageIpnMonitor.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
     public function heartbeatResponse($response = array(), $data = array())
60 60
     {
61 61
         // does this heartbeat contain our data ?
62
-        if (! isset($data['espresso_thank_you_page'])) {
62
+        if ( ! isset($data['espresso_thank_you_page'])) {
63 63
             return $response;
64 64
         }
65 65
         // check for reg_url_link in the incoming heartbeat data
66
-        if (! isset($data['espresso_thank_you_page']['e_reg_url_link'])) {
66
+        if ( ! isset($data['espresso_thank_you_page']['e_reg_url_link'])) {
67 67
             $response['espresso_thank_you_page'] = array(
68 68
                 'errors' => ! empty($notices['errors'])
69 69
                     ? $notices['errors']
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
      */
110 110
     private function initializeThankYouPageAndTransaction($response, $data)
111 111
     {
112
-        require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php';
112
+        require_once EE_MODULES.'thank_you_page/EED_Thank_You_Page.module.php';
113 113
         // set_definitions, instantiate the thank you page class, and get the ball rolling
114 114
         EED_Thank_You_Page::set_definitions();
115 115
         $this->thank_you_page = EED_Thank_You_Page::instance();
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         // get TXN
120 120
         $transaction = $this->thank_you_page->get_txn();
121 121
         // no TXN? then get out
122
-        if (! $transaction instanceof EE_Transaction) {
122
+        if ( ! $transaction instanceof EE_Transaction) {
123 123
             $notices = EE_Error::get_notices();
124 124
             $response['espresso_thank_you_page'] = array(
125 125
                 'errors' => ! empty($notices['errors'])
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
         // then check for payments
187 187
         $payments = $this->thank_you_page->get_txn_payments($since);
188 188
         // has a payment been processed ?
189
-        if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) {
189
+        if ( ! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) {
190 190
             if ($since) {
191 191
                 $response['espresso_thank_you_page'] = array(
192 192
                     'new_payments'        => $this->thank_you_page->get_new_payments($payments),
Please login to merge, or discard this patch.
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -21,206 +21,206 @@
 block discarded – undo
21 21
 class ThankYouPageIpnMonitor
22 22
 {
23 23
 
24
-    /**
25
-     * @var EED_Thank_You_Page $thank_you_page
26
-     */
27
-    private $thank_you_page;
28
-
29
-    /**
30
-     * @var EE_Transaction $transaction
31
-     */
32
-    private $transaction;
33
-
34
-
35
-    /**
36
-     * EventEditorHeartbeat constructor.
37
-     */
38
-    public function __construct()
39
-    {
40
-        add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 3);
41
-        add_filter('heartbeat_nopriv_received', array($this, 'heartbeatResponse'), 10, 3);
42
-    }
43
-
44
-
45
-    /**
46
-     * thank_you_page_IPN_monitor
47
-     * this basically just pulls the TXN based on the reg_url_link sent from the server,
48
-     * then checks that the TXN status is not failed, and that no other errors have been generated.
49
-     * it also calculates the IPN wait time since the Thank You page was first loaded
50
-     *
51
-     * @param array $response
52
-     * @param array $data
53
-     * @return array
54
-     * @throws EE_Error
55
-     * @throws InvalidDataTypeException
56
-     * @throws InvalidInterfaceException
57
-     * @throws InvalidArgumentException
58
-     */
59
-    public function heartbeatResponse($response = array(), $data = array())
60
-    {
61
-        // does this heartbeat contain our data ?
62
-        if (! isset($data['espresso_thank_you_page'])) {
63
-            return $response;
64
-        }
65
-        // check for reg_url_link in the incoming heartbeat data
66
-        if (! isset($data['espresso_thank_you_page']['e_reg_url_link'])) {
67
-            $response['espresso_thank_you_page'] = array(
68
-                'errors' => ! empty($notices['errors'])
69
-                    ? $notices['errors']
70
-                    : __(
71
-                        'No transaction information could be retrieved because the registration URL link is missing or invalid.',
72
-                        'event_espresso'
73
-                    ),
74
-            );
75
-            return $response;
76
-        }
77
-        // kk heartbeat has our data
78
-        $response = $this->initializeThankYouPageAndTransaction($response, $data);
79
-        // if something went wrong...
80
-        if (isset($response['espresso_thank_you_page']['errors'])) {
81
-            return $response;
82
-        }
83
-        // grab transient of Transaction's status
84
-        $txn_status = isset($data['espresso_thank_you_page']['txn_status'])
85
-            ? $data['espresso_thank_you_page']['txn_status']
86
-            : null;
87
-        $response = $this->getTransactionDetails($txn_status, $response, $data);
88
-        // no payment data yet?
89
-        if (isset($response['espresso_thank_you_page']['still_waiting'])) {
90
-            return $response;
91
-        }
92
-        // TXN is happening so let's get the payments now
93
-        // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked
94
-        $since = isset($data['espresso_thank_you_page']['get_payments_since'])
95
-            ? $data['espresso_thank_you_page']['get_payments_since']
96
-            : 0;
97
-        return $this->paymentDetails($since);
98
-    }
99
-
100
-
101
-    /**
102
-     * @param array $response
103
-     * @param array $data
104
-     * @return array
105
-     * @throws EE_Error
106
-     * @throws InvalidArgumentException
107
-     * @throws InvalidDataTypeException
108
-     * @throws InvalidInterfaceException
109
-     */
110
-    private function initializeThankYouPageAndTransaction($response, $data)
111
-    {
112
-        require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php';
113
-        // set_definitions, instantiate the thank you page class, and get the ball rolling
114
-        EED_Thank_You_Page::set_definitions();
115
-        $this->thank_you_page = EED_Thank_You_Page::instance();
116
-        $this->thank_you_page->set_reg_url_link($data['espresso_thank_you_page']['e_reg_url_link']);
117
-        $this->thank_you_page->init();
118
-        $response['espresso_thank_you_page'] = array();
119
-        // get TXN
120
-        $transaction = $this->thank_you_page->get_txn();
121
-        // no TXN? then get out
122
-        if (! $transaction instanceof EE_Transaction) {
123
-            $notices = EE_Error::get_notices();
124
-            $response['espresso_thank_you_page'] = array(
125
-                'errors' => ! empty($notices['errors'])
126
-                    ? $notices['errors']
127
-                    : sprintf(
128
-                        __(
129
-                            'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)',
130
-                            'event_espresso'
131
-                        ),
132
-                        __LINE__
133
-                    ),
134
-            );
135
-            return $response;
136
-        }
137
-        $this->transaction = $transaction;
138
-        return $response;
139
-    }
140
-
141
-
142
-    /**
143
-     * @param string $txn_status
144
-     * @param array  $response
145
-     * @param array  $data
146
-     * @return array
147
-     * @throws EE_Error
148
-     */
149
-    private function getTransactionDetails($txn_status, $response, $data)
150
-    {
151
-        // has the TXN status changed since we last checked (or empty because this is the first time running through this code)?
152
-        if ($txn_status !== $this->transaction->status_ID()) {
153
-            // switch between two possible basic outcomes
154
-            switch ($this->transaction->status_ID()) {
155
-                // TXN has been updated in some way
156
-                case EEM_Transaction::overpaid_status_code:
157
-                case EEM_Transaction::complete_status_code:
158
-                case EEM_Transaction::incomplete_status_code:
159
-                    // send updated TXN results back to client,
160
-                    $response['espresso_thank_you_page'] = array(
161
-                        'transaction_details' => $this->thank_you_page->get_transaction_details(),
162
-                        'txn_status'          => $this->transaction->status_ID(),
163
-                    );
164
-                    return $response;
165
-                // or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back...
166
-                case EEM_Transaction::failed_status_code:
167
-                default:
168
-                    // keep on waiting...
169
-                    return $this->updateServerWaitTime($data['espresso_thank_you_page']);
170
-            }
171
-            // or is the TXN still failed (never been updated) ???
172
-        } elseif ($this->transaction->failed()) {
173
-            // keep on waiting...
174
-            return $this->updateServerWaitTime($data['espresso_thank_you_page']);
175
-        }
176
-    }
177
-
178
-
179
-    /**
180
-     * @param int $since
181
-     * @return array
182
-     * @throws EE_Error
183
-     */
184
-    private function paymentDetails($since)
185
-    {
186
-        // then check for payments
187
-        $payments = $this->thank_you_page->get_txn_payments($since);
188
-        // has a payment been processed ?
189
-        if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) {
190
-            if ($since) {
191
-                $response['espresso_thank_you_page'] = array(
192
-                    'new_payments'        => $this->thank_you_page->get_new_payments($payments),
193
-                    'transaction_details' => $this->thank_you_page->get_transaction_details(),
194
-                    'txn_status'          => $this->transaction->status_ID(),
195
-                );
196
-            } else {
197
-                $response['espresso_thank_you_page']['payment_details'] = $this->thank_you_page->get_payment_details(
198
-                    $payments
199
-                );
200
-            }
201
-            // reset time to check for payments
202
-            $response['espresso_thank_you_page']['get_payments_since'] = time();
203
-        } else {
204
-            $response['espresso_thank_you_page']['get_payments_since'] = $since;
205
-        }
206
-        return $response;
207
-    }
208
-
209
-
210
-    /**
211
-     * @param array $thank_you_page_data    thank you page portion of the incoming JSON array
212
-     *                                      from the WP heartbeat data
213
-     * @return array
214
-     * @throws EE_Error
215
-     */
216
-    private function updateServerWaitTime($thank_you_page_data)
217
-    {
218
-        $response['espresso_thank_you_page'] = array(
219
-            'still_waiting' => isset($thank_you_page_data['initial_access'])
220
-                ? time() - $thank_you_page_data['initial_access']
221
-                : 0,
222
-            'txn_status'    => $this->transaction->status_ID(),
223
-        );
224
-        return $response;
225
-    }
24
+	/**
25
+	 * @var EED_Thank_You_Page $thank_you_page
26
+	 */
27
+	private $thank_you_page;
28
+
29
+	/**
30
+	 * @var EE_Transaction $transaction
31
+	 */
32
+	private $transaction;
33
+
34
+
35
+	/**
36
+	 * EventEditorHeartbeat constructor.
37
+	 */
38
+	public function __construct()
39
+	{
40
+		add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 3);
41
+		add_filter('heartbeat_nopriv_received', array($this, 'heartbeatResponse'), 10, 3);
42
+	}
43
+
44
+
45
+	/**
46
+	 * thank_you_page_IPN_monitor
47
+	 * this basically just pulls the TXN based on the reg_url_link sent from the server,
48
+	 * then checks that the TXN status is not failed, and that no other errors have been generated.
49
+	 * it also calculates the IPN wait time since the Thank You page was first loaded
50
+	 *
51
+	 * @param array $response
52
+	 * @param array $data
53
+	 * @return array
54
+	 * @throws EE_Error
55
+	 * @throws InvalidDataTypeException
56
+	 * @throws InvalidInterfaceException
57
+	 * @throws InvalidArgumentException
58
+	 */
59
+	public function heartbeatResponse($response = array(), $data = array())
60
+	{
61
+		// does this heartbeat contain our data ?
62
+		if (! isset($data['espresso_thank_you_page'])) {
63
+			return $response;
64
+		}
65
+		// check for reg_url_link in the incoming heartbeat data
66
+		if (! isset($data['espresso_thank_you_page']['e_reg_url_link'])) {
67
+			$response['espresso_thank_you_page'] = array(
68
+				'errors' => ! empty($notices['errors'])
69
+					? $notices['errors']
70
+					: __(
71
+						'No transaction information could be retrieved because the registration URL link is missing or invalid.',
72
+						'event_espresso'
73
+					),
74
+			);
75
+			return $response;
76
+		}
77
+		// kk heartbeat has our data
78
+		$response = $this->initializeThankYouPageAndTransaction($response, $data);
79
+		// if something went wrong...
80
+		if (isset($response['espresso_thank_you_page']['errors'])) {
81
+			return $response;
82
+		}
83
+		// grab transient of Transaction's status
84
+		$txn_status = isset($data['espresso_thank_you_page']['txn_status'])
85
+			? $data['espresso_thank_you_page']['txn_status']
86
+			: null;
87
+		$response = $this->getTransactionDetails($txn_status, $response, $data);
88
+		// no payment data yet?
89
+		if (isset($response['espresso_thank_you_page']['still_waiting'])) {
90
+			return $response;
91
+		}
92
+		// TXN is happening so let's get the payments now
93
+		// if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked
94
+		$since = isset($data['espresso_thank_you_page']['get_payments_since'])
95
+			? $data['espresso_thank_you_page']['get_payments_since']
96
+			: 0;
97
+		return $this->paymentDetails($since);
98
+	}
99
+
100
+
101
+	/**
102
+	 * @param array $response
103
+	 * @param array $data
104
+	 * @return array
105
+	 * @throws EE_Error
106
+	 * @throws InvalidArgumentException
107
+	 * @throws InvalidDataTypeException
108
+	 * @throws InvalidInterfaceException
109
+	 */
110
+	private function initializeThankYouPageAndTransaction($response, $data)
111
+	{
112
+		require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php';
113
+		// set_definitions, instantiate the thank you page class, and get the ball rolling
114
+		EED_Thank_You_Page::set_definitions();
115
+		$this->thank_you_page = EED_Thank_You_Page::instance();
116
+		$this->thank_you_page->set_reg_url_link($data['espresso_thank_you_page']['e_reg_url_link']);
117
+		$this->thank_you_page->init();
118
+		$response['espresso_thank_you_page'] = array();
119
+		// get TXN
120
+		$transaction = $this->thank_you_page->get_txn();
121
+		// no TXN? then get out
122
+		if (! $transaction instanceof EE_Transaction) {
123
+			$notices = EE_Error::get_notices();
124
+			$response['espresso_thank_you_page'] = array(
125
+				'errors' => ! empty($notices['errors'])
126
+					? $notices['errors']
127
+					: sprintf(
128
+						__(
129
+							'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)',
130
+							'event_espresso'
131
+						),
132
+						__LINE__
133
+					),
134
+			);
135
+			return $response;
136
+		}
137
+		$this->transaction = $transaction;
138
+		return $response;
139
+	}
140
+
141
+
142
+	/**
143
+	 * @param string $txn_status
144
+	 * @param array  $response
145
+	 * @param array  $data
146
+	 * @return array
147
+	 * @throws EE_Error
148
+	 */
149
+	private function getTransactionDetails($txn_status, $response, $data)
150
+	{
151
+		// has the TXN status changed since we last checked (or empty because this is the first time running through this code)?
152
+		if ($txn_status !== $this->transaction->status_ID()) {
153
+			// switch between two possible basic outcomes
154
+			switch ($this->transaction->status_ID()) {
155
+				// TXN has been updated in some way
156
+				case EEM_Transaction::overpaid_status_code:
157
+				case EEM_Transaction::complete_status_code:
158
+				case EEM_Transaction::incomplete_status_code:
159
+					// send updated TXN results back to client,
160
+					$response['espresso_thank_you_page'] = array(
161
+						'transaction_details' => $this->thank_you_page->get_transaction_details(),
162
+						'txn_status'          => $this->transaction->status_ID(),
163
+					);
164
+					return $response;
165
+				// or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back...
166
+				case EEM_Transaction::failed_status_code:
167
+				default:
168
+					// keep on waiting...
169
+					return $this->updateServerWaitTime($data['espresso_thank_you_page']);
170
+			}
171
+			// or is the TXN still failed (never been updated) ???
172
+		} elseif ($this->transaction->failed()) {
173
+			// keep on waiting...
174
+			return $this->updateServerWaitTime($data['espresso_thank_you_page']);
175
+		}
176
+	}
177
+
178
+
179
+	/**
180
+	 * @param int $since
181
+	 * @return array
182
+	 * @throws EE_Error
183
+	 */
184
+	private function paymentDetails($since)
185
+	{
186
+		// then check for payments
187
+		$payments = $this->thank_you_page->get_txn_payments($since);
188
+		// has a payment been processed ?
189
+		if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) {
190
+			if ($since) {
191
+				$response['espresso_thank_you_page'] = array(
192
+					'new_payments'        => $this->thank_you_page->get_new_payments($payments),
193
+					'transaction_details' => $this->thank_you_page->get_transaction_details(),
194
+					'txn_status'          => $this->transaction->status_ID(),
195
+				);
196
+			} else {
197
+				$response['espresso_thank_you_page']['payment_details'] = $this->thank_you_page->get_payment_details(
198
+					$payments
199
+				);
200
+			}
201
+			// reset time to check for payments
202
+			$response['espresso_thank_you_page']['get_payments_since'] = time();
203
+		} else {
204
+			$response['espresso_thank_you_page']['get_payments_since'] = $since;
205
+		}
206
+		return $response;
207
+	}
208
+
209
+
210
+	/**
211
+	 * @param array $thank_you_page_data    thank you page portion of the incoming JSON array
212
+	 *                                      from the WP heartbeat data
213
+	 * @return array
214
+	 * @throws EE_Error
215
+	 */
216
+	private function updateServerWaitTime($thank_you_page_data)
217
+	{
218
+		$response['espresso_thank_you_page'] = array(
219
+			'still_waiting' => isset($thank_you_page_data['initial_access'])
220
+				? time() - $thank_you_page_data['initial_access']
221
+				: 0,
222
+			'txn_status'    => $this->transaction->status_ID(),
223
+		);
224
+		return $response;
225
+	}
226 226
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.76.rc.004');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.76.rc.004');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.
core/services/payment_methods/forms/PayPalSettingsForm.php 1 patch
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -19,201 +19,201 @@
 block discarded – undo
19 19
  */
20 20
 class PayPalSettingsForm extends EE_Payment_Method_Form
21 21
 {
22
-    /**
23
-     * @var string of HTML being the help tab link
24
-     */
25
-    protected $helpTabLink;
22
+	/**
23
+	 * @var string of HTML being the help tab link
24
+	 */
25
+	protected $helpTabLink;
26 26
 
27
-    public function __construct(array $options_array = array(), $help_tab_link = '')
28
-    {
29
-        $this->helpTabLink = $help_tab_link;
30
-        $options_array = array_replace_recursive(
31
-            array(
32
-                'extra_meta_inputs' => array(
33
-                    'api_username' => new EE_Text_Input(
34
-                        array(
35
-                            'html_label_text' => sprintf(
36
-                                // translators: %s link to help doc
37
-                                esc_html__('API Username %s', 'event_espresso'),
38
-                                $help_tab_link
39
-                            ),
40
-                            'required'        => true,
41
-                        )
42
-                    ),
43
-                    'api_password' => new EE_Text_Input(
44
-                        array(
45
-                            'html_label_text' => sprintf(
46
-                                // translators: %s link to help doc
47
-                                esc_html__('API Password %s', 'event_espresso'),
48
-                                $help_tab_link
49
-                            ),
50
-                            'required'        => true,
51
-                        )
52
-                    ),
53
-                    'api_signature' => new EE_Text_Input(
54
-                        array(
55
-                            'html_label_text' => sprintf(
56
-                                // translators: %s link to help doc
57
-                                esc_html__('API Signature %s', 'event_espresso'),
58
-                                $help_tab_link
59
-                            ),
60
-                            'required'        => true,
61
-                        )
62
-                    ),
63
-                )
64
-            ),
65
-            $options_array
66
-        );
67
-        parent::__construct($options_array);
68
-    }
27
+	public function __construct(array $options_array = array(), $help_tab_link = '')
28
+	{
29
+		$this->helpTabLink = $help_tab_link;
30
+		$options_array = array_replace_recursive(
31
+			array(
32
+				'extra_meta_inputs' => array(
33
+					'api_username' => new EE_Text_Input(
34
+						array(
35
+							'html_label_text' => sprintf(
36
+								// translators: %s link to help doc
37
+								esc_html__('API Username %s', 'event_espresso'),
38
+								$help_tab_link
39
+							),
40
+							'required'        => true,
41
+						)
42
+					),
43
+					'api_password' => new EE_Text_Input(
44
+						array(
45
+							'html_label_text' => sprintf(
46
+								// translators: %s link to help doc
47
+								esc_html__('API Password %s', 'event_espresso'),
48
+								$help_tab_link
49
+							),
50
+							'required'        => true,
51
+						)
52
+					),
53
+					'api_signature' => new EE_Text_Input(
54
+						array(
55
+							'html_label_text' => sprintf(
56
+								// translators: %s link to help doc
57
+								esc_html__('API Signature %s', 'event_espresso'),
58
+								$help_tab_link
59
+							),
60
+							'required'        => true,
61
+						)
62
+					),
63
+				)
64
+			),
65
+			$options_array
66
+		);
67
+		parent::__construct($options_array);
68
+	}
69 69
 
70
-    /**
71
-     * Tests the the PayPal API credentials work ok
72
-     * @return string of an error using the credentials, otherwise, if the credentials work, returns a blank string
73
-     * @throws EE_Error
74
-     */
75
-    protected function checkForCredentialsErrors()
76
-    {
77
-        $request_params = array(
78
-            'METHOD'    => 'GetBalance',
79
-            'VERSION'   => '204.0',
80
-            'USER'      => urlencode($this->get_input_value('api_username')),
81
-            'PWD'       => urlencode($this->get_input_value('api_password')),
82
-            'SIGNATURE' => urlencode($this->get_input_value('api_signature')),
83
-        );
84
-        $gateway_url = $this->get_input_value('PMD_debug_mode')
85
-            ? 'https://api-3t.sandbox.paypal.com/nvp'
86
-            : 'https://api-3t.paypal.com/nvp';
87
-        // Request Customer Details.
88
-        $response = wp_remote_post(
89
-            $gateway_url,
90
-            array(
91
-                'method'      => 'POST',
92
-                'timeout'     => 45,
93
-                'httpversion' => '1.1',
94
-                'cookies'     => array(),
95
-                'headers'     => array(),
96
-                'body'        => http_build_query($request_params, '', '&'),
97
-            )
98
-        );
99
-        if (is_wp_error($response) || empty($response['body'])) {
100
-            // If we got here then there was an error in this request.
101
-            // maybe is turned off. We don't know the credentials are invalid
102
-            EE_Error::add_error(
103
-                sprintf(
104
-                    // translators: %1$s Error message received from PayPal
105
-                    esc_html__(
106
-                        // @codingStandardsIgnoreStart
107
-                        'Your PayPal credentials could not be verified. The following error occurred while communicating with PayPal: %1$s',
108
-                        // @codingStandardsIgnoreEnd
109
-                        'event_espresso'
110
-                    ),
111
-                    $response->get_error_message()
112
-                ),
113
-                __FILE__,
114
-                __FUNCTION__,
115
-                __LINE__
116
-            );
117
-        }
118
-        $response_args = array();
119
-        parse_str(urldecode($response['body']), $response_args);
70
+	/**
71
+	 * Tests the the PayPal API credentials work ok
72
+	 * @return string of an error using the credentials, otherwise, if the credentials work, returns a blank string
73
+	 * @throws EE_Error
74
+	 */
75
+	protected function checkForCredentialsErrors()
76
+	{
77
+		$request_params = array(
78
+			'METHOD'    => 'GetBalance',
79
+			'VERSION'   => '204.0',
80
+			'USER'      => urlencode($this->get_input_value('api_username')),
81
+			'PWD'       => urlencode($this->get_input_value('api_password')),
82
+			'SIGNATURE' => urlencode($this->get_input_value('api_signature')),
83
+		);
84
+		$gateway_url = $this->get_input_value('PMD_debug_mode')
85
+			? 'https://api-3t.sandbox.paypal.com/nvp'
86
+			: 'https://api-3t.paypal.com/nvp';
87
+		// Request Customer Details.
88
+		$response = wp_remote_post(
89
+			$gateway_url,
90
+			array(
91
+				'method'      => 'POST',
92
+				'timeout'     => 45,
93
+				'httpversion' => '1.1',
94
+				'cookies'     => array(),
95
+				'headers'     => array(),
96
+				'body'        => http_build_query($request_params, '', '&'),
97
+			)
98
+		);
99
+		if (is_wp_error($response) || empty($response['body'])) {
100
+			// If we got here then there was an error in this request.
101
+			// maybe is turned off. We don't know the credentials are invalid
102
+			EE_Error::add_error(
103
+				sprintf(
104
+					// translators: %1$s Error message received from PayPal
105
+					esc_html__(
106
+						// @codingStandardsIgnoreStart
107
+						'Your PayPal credentials could not be verified. The following error occurred while communicating with PayPal: %1$s',
108
+						// @codingStandardsIgnoreEnd
109
+						'event_espresso'
110
+					),
111
+					$response->get_error_message()
112
+				),
113
+				__FILE__,
114
+				__FUNCTION__,
115
+				__LINE__
116
+			);
117
+		}
118
+		$response_args = array();
119
+		parse_str(urldecode($response['body']), $response_args);
120 120
 
121
-        if (empty($response_args['ACK'])) {
122
-            EE_Error::add_error(
123
-                esc_html__(
124
-                    'Your PayPal credentials could not be verified. Part of their response was missing.',
125
-                    'event_espresso'
126
-                ),
127
-                __FILE__,
128
-                __FUNCTION__,
129
-                __LINE__
130
-            );
131
-        }
132
-        if (in_array(
133
-            $response_args['ACK'],
134
-            array(
135
-                'Success',
136
-                'SuccessWithWarning'
137
-            ),
138
-            true
139
-        )
140
-        ) {
141
-            return '';
142
-        } else {
143
-            return sprintf(
144
-                // translators: %1$s: PayPal response message, %2$s: PayPal response code
145
-                esc_html__(
146
-                    // @codingStandardsIgnoreStart
147
-                    'Your PayPal API credentials appear to be invalid. PayPal said "%1$s (%2$s)". Please see tips below.',
148
-                    // @codingStandardsIgnoreEnd
149
-                    'event_espresso'
150
-                ),
151
-                isset($response_args['L_LONGMESSAGE0'])
152
-                    ? $response_args['L_LONGMESSAGE0']
153
-                    : esc_html__('No error message received from PayPal', 'event_espresso'),
154
-                isset($response_args['L_ERRORCODE0']) ? $response_args['L_ERRORCODE0'] : 0
155
-            );
156
-        }
157
-    }
121
+		if (empty($response_args['ACK'])) {
122
+			EE_Error::add_error(
123
+				esc_html__(
124
+					'Your PayPal credentials could not be verified. Part of their response was missing.',
125
+					'event_espresso'
126
+				),
127
+				__FILE__,
128
+				__FUNCTION__,
129
+				__LINE__
130
+			);
131
+		}
132
+		if (in_array(
133
+			$response_args['ACK'],
134
+			array(
135
+				'Success',
136
+				'SuccessWithWarning'
137
+			),
138
+			true
139
+		)
140
+		) {
141
+			return '';
142
+		} else {
143
+			return sprintf(
144
+				// translators: %1$s: PayPal response message, %2$s: PayPal response code
145
+				esc_html__(
146
+					// @codingStandardsIgnoreStart
147
+					'Your PayPal API credentials appear to be invalid. PayPal said "%1$s (%2$s)". Please see tips below.',
148
+					// @codingStandardsIgnoreEnd
149
+					'event_espresso'
150
+				),
151
+				isset($response_args['L_LONGMESSAGE0'])
152
+					? $response_args['L_LONGMESSAGE0']
153
+					: esc_html__('No error message received from PayPal', 'event_espresso'),
154
+				isset($response_args['L_ERRORCODE0']) ? $response_args['L_ERRORCODE0'] : 0
155
+			);
156
+		}
157
+	}
158 158
 
159
-    /**
160
-     * Gets the HTML to show the link to the help tab
161
-     * @return string
162
-     */
163
-    protected function helpTabLink()
164
-    {
165
-        return $this->helpTabLink;
166
-    }
159
+	/**
160
+	 * Gets the HTML to show the link to the help tab
161
+	 * @return string
162
+	 */
163
+	protected function helpTabLink()
164
+	{
165
+		return $this->helpTabLink;
166
+	}
167 167
 
168
-    /**
169
-     * Does the normal validation, but also verifies the PayPal API credentials work.
170
-     * If they don't, sets a validation error on the entire form, and adds validation errors (which are really more
171
-     * tips) on each of the inputs that could be the cause of the problem.
172
-     * @throws EE_Error
173
-     */
174
-    public function _validate()
175
-    {
176
-        parent::_validate();
177
-        $credentials_message = $this->checkForCredentialsErrors();
178
-        if ($credentials_message !== '') {
179
-            $this->add_validation_error($credentials_message);
180
-            $this->get_input('PMD_debug_mode')->add_validation_error(
181
-                esc_html__(
182
-                    // @codingStandardsIgnoreStart
183
-                    'If you are using PayPal Sandbox (test) credentials, Debug mode should be set to "Yes". Otherwise, if you are using live PayPal credentials, set this to "No".',
184
-                    // @codingStandardsIgnoreEnd
185
-                    'event_espresso'
186
-                )
187
-            );
188
-            $this->get_input('api_username')->add_validation_error(
189
-                sprintf(
190
-                    // translators: $1$s HTML for a link to the help tab
191
-                    esc_html__(
192
-                        'Are you sure this is your API username, not your login username? %1$s',
193
-                        'event_espresso'
194
-                    ),
195
-                    $this->helpTabLink()
196
-                )
197
-            );
198
-            $this->get_input('api_password')->add_validation_error(
199
-                sprintf(
200
-                    // translators: $1$s HTML for a link to the help tab
201
-                    esc_html__(
202
-                        'Are you sure this is your API password, not your login password? %1$s',
203
-                        'event_espresso'
204
-                    ),
205
-                    $this->helpTabLink()
206
-                )
207
-            );
208
-            $this->get_input('api_signature')->add_validation_error(
209
-                sprintf(
210
-                    // translators: $1$s HTML for a link to the help tab
211
-                    esc_html__('Please verify your API signature is correct. %1$s', 'event_espresso'),
212
-                    $this->helpTabLink()
213
-                )
214
-            );
215
-        }
216
-    }
168
+	/**
169
+	 * Does the normal validation, but also verifies the PayPal API credentials work.
170
+	 * If they don't, sets a validation error on the entire form, and adds validation errors (which are really more
171
+	 * tips) on each of the inputs that could be the cause of the problem.
172
+	 * @throws EE_Error
173
+	 */
174
+	public function _validate()
175
+	{
176
+		parent::_validate();
177
+		$credentials_message = $this->checkForCredentialsErrors();
178
+		if ($credentials_message !== '') {
179
+			$this->add_validation_error($credentials_message);
180
+			$this->get_input('PMD_debug_mode')->add_validation_error(
181
+				esc_html__(
182
+					// @codingStandardsIgnoreStart
183
+					'If you are using PayPal Sandbox (test) credentials, Debug mode should be set to "Yes". Otherwise, if you are using live PayPal credentials, set this to "No".',
184
+					// @codingStandardsIgnoreEnd
185
+					'event_espresso'
186
+				)
187
+			);
188
+			$this->get_input('api_username')->add_validation_error(
189
+				sprintf(
190
+					// translators: $1$s HTML for a link to the help tab
191
+					esc_html__(
192
+						'Are you sure this is your API username, not your login username? %1$s',
193
+						'event_espresso'
194
+					),
195
+					$this->helpTabLink()
196
+				)
197
+			);
198
+			$this->get_input('api_password')->add_validation_error(
199
+				sprintf(
200
+					// translators: $1$s HTML for a link to the help tab
201
+					esc_html__(
202
+						'Are you sure this is your API password, not your login password? %1$s',
203
+						'event_espresso'
204
+					),
205
+					$this->helpTabLink()
206
+				)
207
+			);
208
+			$this->get_input('api_signature')->add_validation_error(
209
+				sprintf(
210
+					// translators: $1$s HTML for a link to the help tab
211
+					esc_html__('Please verify your API signature is correct. %1$s', 'event_espresso'),
212
+					$this->helpTabLink()
213
+				)
214
+			);
215
+		}
216
+	}
217 217
 }
218 218
 // End of file PayPalSettingsForm.php
219 219
 // Location: ${NAMESPACE}/PayPalSettingsForm.php
Please login to merge, or discard this patch.
caffeinated/payment_methods/Paypal_Pro/forms/PayPalProSettingsForm.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -17,30 +17,30 @@
 block discarded – undo
17 17
  */
18 18
 class PayPalProSettingsForm extends PayPalSettingsForm
19 19
 {
20
-    /**
21
-     * SettingsForm constructor.
22
-     *
23
-     * @param array $options_array
24
-     * @param string $help_tab_link
25
-     */
26
-    public function __construct(array $options_array = array(), $help_tab_link = '')
27
-    {
28
-        $options_array = array_replace_recursive(
29
-            array(
30
-                'extra_meta_inputs' => array(
31
-                    'credit_card_types' => new EE_Checkbox_Multi_Input(
32
-                        EE_PMT_Paypal_Pro::card_types_supported(),
33
-                        array(
34
-                            'html_label_text' => __('Card Types Supported', 'event_espresso'),
35
-                            'required' => true
36
-                        )
37
-                    ),
38
-                )
39
-            ),
40
-            $options_array
41
-        );
42
-        parent::__construct($options_array, $help_tab_link);
43
-    }
20
+	/**
21
+	 * SettingsForm constructor.
22
+	 *
23
+	 * @param array $options_array
24
+	 * @param string $help_tab_link
25
+	 */
26
+	public function __construct(array $options_array = array(), $help_tab_link = '')
27
+	{
28
+		$options_array = array_replace_recursive(
29
+			array(
30
+				'extra_meta_inputs' => array(
31
+					'credit_card_types' => new EE_Checkbox_Multi_Input(
32
+						EE_PMT_Paypal_Pro::card_types_supported(),
33
+						array(
34
+							'html_label_text' => __('Card Types Supported', 'event_espresso'),
35
+							'required' => true
36
+						)
37
+					),
38
+				)
39
+			),
40
+			$options_array
41
+		);
42
+		parent::__construct($options_array, $help_tab_link);
43
+	}
44 44
 }
45 45
 // End of file SettingsForm.php
46 46
 // Location: EventEspresso/caffeinated/payment_methods/PayPal_Pro/forms/PayPalProSettingsForm.php
Please login to merge, or discard this patch.
payment_methods/Paypal_Express/forms/SettingsForm.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -19,53 +19,53 @@
 block discarded – undo
19 19
  */
20 20
 class SettingsForm extends PayPalSettingsForm
21 21
 {
22
-    /**
23
-     * SettingsForm constructor.
24
-     *
25
-     * @param array $options_array
26
-     * @param string $help_tab_link
27
-     * @throws InvalidDataTypeException
28
-     * @throws InvalidInterfaceException
29
-     * @throws InvalidArgumentException
30
-     */
31
-    public function __construct(array $options_array = array(), $help_tab_link = '')
32
-    {
33
-        $options_array = array_replace_recursive(
34
-            array(
35
-                'extra_meta_inputs' => array(
36
-                    'request_shipping_addr' => new EE_Yes_No_Input(
37
-                        array(
38
-                            'html_label_text' => sprintf(
39
-                                esc_html__('Request Shipping Address %s', 'event_espresso'),
40
-                                $help_tab_link
41
-                            ),
42
-                            'html_help_text'  => esc_html__(
43
-                            // @codingStandardsIgnoreStart
44
-                                'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.',
45
-                                // @codingStandardsIgnoreEnd
46
-                                'event_espresso'
47
-                            ),
48
-                            'required'        => true,
49
-                            'default'         => false,
50
-                        )
51
-                    ),
52
-                    'image_url' => new EE_Admin_File_Uploader_Input(
53
-                        array(
54
-                            'html_label_text' => sprintf(
55
-                                esc_html__('Image URL %s', 'event_espresso'),
56
-                                $help_tab_link
57
-                            ),
58
-                            'html_help_text'  => esc_html__(
59
-                                'Used for your business/personal logo on the PayPal page',
60
-                                'event_espresso'
61
-                            ),
62
-                            'required'        => false,
63
-                        )
64
-                    ),
65
-                )
66
-            ),
67
-            $options_array
68
-        );
69
-        parent::__construct($options_array, $help_tab_link);
70
-    }
22
+	/**
23
+	 * SettingsForm constructor.
24
+	 *
25
+	 * @param array $options_array
26
+	 * @param string $help_tab_link
27
+	 * @throws InvalidDataTypeException
28
+	 * @throws InvalidInterfaceException
29
+	 * @throws InvalidArgumentException
30
+	 */
31
+	public function __construct(array $options_array = array(), $help_tab_link = '')
32
+	{
33
+		$options_array = array_replace_recursive(
34
+			array(
35
+				'extra_meta_inputs' => array(
36
+					'request_shipping_addr' => new EE_Yes_No_Input(
37
+						array(
38
+							'html_label_text' => sprintf(
39
+								esc_html__('Request Shipping Address %s', 'event_espresso'),
40
+								$help_tab_link
41
+							),
42
+							'html_help_text'  => esc_html__(
43
+							// @codingStandardsIgnoreStart
44
+								'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.',
45
+								// @codingStandardsIgnoreEnd
46
+								'event_espresso'
47
+							),
48
+							'required'        => true,
49
+							'default'         => false,
50
+						)
51
+					),
52
+					'image_url' => new EE_Admin_File_Uploader_Input(
53
+						array(
54
+							'html_label_text' => sprintf(
55
+								esc_html__('Image URL %s', 'event_espresso'),
56
+								$help_tab_link
57
+							),
58
+							'html_help_text'  => esc_html__(
59
+								'Used for your business/personal logo on the PayPal page',
60
+								'event_espresso'
61
+							),
62
+							'required'        => false,
63
+						)
64
+					),
65
+				)
66
+			),
67
+			$options_array
68
+		);
69
+		parent::__construct($options_array, $help_tab_link);
70
+	}
71 71
 }
Please login to merge, or discard this patch.