Completed
Branch Gutenberg/master (472310)
by
unknown
93:25 queued 79:25
created
payment_methods/Paypal_Express/EEG_Paypal_Express.gateway.php 2 patches
Indentation   +666 added lines, -666 removed lines patch added patch discarded remove patch
@@ -11,674 +11,674 @@
 block discarded – undo
11 11
  */
12 12
 // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP
13 13
 if (! function_exists('mb_strcut')) {
14
-    /**
15
-     * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
16
-     * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
17
-     * @param $string
18
-     * @param $start
19
-     * @param $length
20
-     * @return bool|string
21
-     */
22
-    function mb_strcut($string, $start, $length = null)
23
-    {
24
-        return mb_substr($string, $start, $length);
25
-    }
14
+	/**
15
+	 * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
16
+	 * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
17
+	 * @param $string
18
+	 * @param $start
19
+	 * @param $length
20
+	 * @return bool|string
21
+	 */
22
+	function mb_strcut($string, $start, $length = null)
23
+	{
24
+		return mb_substr($string, $start, $length);
25
+	}
26 26
 }
27 27
 class EEG_Paypal_Express extends EE_Offsite_Gateway
28 28
 {
29 29
 
30
-    /**
31
-     * Merchant API Username.
32
-     *
33
-     * @var string
34
-     */
35
-    protected $_api_username;
36
-
37
-    /**
38
-     * Merchant API Password.
39
-     *
40
-     * @var string
41
-     */
42
-    protected $_api_password;
43
-
44
-    /**
45
-     * API Signature.
46
-     *
47
-     * @var string
48
-     */
49
-    protected $_api_signature;
50
-
51
-    /**
52
-     * Request Shipping address on PP checkout page.
53
-     *
54
-     * @var string
55
-     */
56
-    protected $_request_shipping_addr;
57
-
58
-    /**
59
-     * Business/personal logo.
60
-     *
61
-     * @var string
62
-     */
63
-    protected $_image_url;
64
-
65
-    /**
66
-     * gateway URL variable
67
-     *
68
-     * @var string
69
-     */
70
-    protected $_base_gateway_url = '';
71
-
72
-
73
-
74
-    /**
75
-     * EEG_Paypal_Express constructor.
76
-     */
77
-    public function __construct()
78
-    {
79
-        $this->_currencies_supported = array(
80
-            'USD',
81
-            'AUD',
82
-            'BRL',
83
-            'CAD',
84
-            'CZK',
85
-            'DKK',
86
-            'EUR',
87
-            'HKD',
88
-            'HUF',
89
-            'ILS',
90
-            'JPY',
91
-            'MYR',
92
-            'MXN',
93
-            'NOK',
94
-            'NZD',
95
-            'PHP',
96
-            'PLN',
97
-            'GBP',
98
-            'RUB',
99
-            'SGD',
100
-            'SEK',
101
-            'CHF',
102
-            'TWD',
103
-            'THB',
104
-            'TRY',
105
-            'INR',
106
-        );
107
-        parent::__construct();
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * Sets the gateway URL variable based on whether debug mode is enabled or not.
114
-     *
115
-     * @param array $settings_array
116
-     */
117
-    public function set_settings($settings_array)
118
-    {
119
-        parent::set_settings($settings_array);
120
-        // Redirect URL.
121
-        $this->_base_gateway_url = $this->_debug_mode
122
-            ? 'https://api-3t.sandbox.paypal.com/nvp'
123
-            : 'https://api-3t.paypal.com/nvp';
124
-    }
125
-
126
-
127
-
128
-    /**
129
-     * @param EEI_Payment $payment
130
-     * @param array       $billing_info
131
-     * @param string      $return_url
132
-     * @param string      $notify_url
133
-     * @param string      $cancel_url
134
-     * @return \EE_Payment|\EEI_Payment
135
-     * @throws \EE_Error
136
-     */
137
-    public function set_redirection_info(
138
-        $payment,
139
-        $billing_info = array(),
140
-        $return_url = null,
141
-        $notify_url = null,
142
-        $cancel_url = null
143
-    ) {
144
-        if (! $payment instanceof EEI_Payment) {
145
-            $payment->set_gateway_response(
146
-                esc_html__(
147
-                    'Error. No associated payment was found.',
148
-                    'event_espresso'
149
-                )
150
-            );
151
-            $payment->set_status($this->_pay_model->failed_status());
152
-            return $payment;
153
-        }
154
-        $transaction = $payment->transaction();
155
-        if (! $transaction instanceof EEI_Transaction) {
156
-            $payment->set_gateway_response(
157
-                esc_html__(
158
-                    'Could not process this payment because it has no associated transaction.',
159
-                    'event_espresso'
160
-                )
161
-            );
162
-            $payment->set_status($this->_pay_model->failed_status());
163
-            return $payment;
164
-        }
165
-        $gateway_formatter = $this->_get_gateway_formatter();
166
-        $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127);
167
-        $primary_registration = $transaction->primary_registration();
168
-        $primary_attendee = $primary_registration instanceof EE_Registration
169
-            ? $primary_registration->attendee()
170
-            : false;
171
-        $locale = explode('-', get_bloginfo('language'));
172
-        // Gather request parameters.
173
-        $token_request_dtls = array(
174
-            'METHOD'                         => 'SetExpressCheckout',
175
-            'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
176
-            'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
177
-            'PAYMENTREQUEST_0_DESC'          => $order_description,
178
-            'RETURNURL'                      => $return_url,
179
-            'CANCELURL'                      => $cancel_url,
180
-            'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
181
-            // Buyer does not need to create a PayPal account to check out.
182
-            // This is referred to as PayPal Account Optional.
183
-            'SOLUTIONTYPE'                   => 'Sole',
184
-            // Locale of the pages displayed by PayPal during Express Checkout.
185
-            'LOCALECODE'                     => $locale[1]
186
-        );
187
-        // Show itemized list.
188
-        $itemized_list = $this->itemize_list($payment, $transaction);
189
-        $token_request_dtls = array_merge($token_request_dtls, $itemized_list);
190
-        // Automatically filling out shipping and contact information.
191
-        if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) {
192
-            // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
193
-            $token_request_dtls['NOSHIPPING'] = '2';
194
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address();
195
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2();
196
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city();
197
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev();
198
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID();
199
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
200
-            $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
201
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
202
-        } elseif (! $this->_request_shipping_addr) {
203
-            // Do not request shipping details on the PP Checkout page.
204
-            $token_request_dtls['NOSHIPPING'] = '1';
205
-            $token_request_dtls['REQCONFIRMSHIPPING'] = '0';
206
-        }
207
-        // Used a business/personal logo on the PayPal page.
208
-        if (! empty($this->_image_url)) {
209
-            $token_request_dtls['LOGOIMG'] = $this->_image_url;
210
-        }
211
-        $token_request_dtls = apply_filters(
212
-            'FHEE__EEG_Paypal_Express__set_redirection_info__arguments',
213
-            $token_request_dtls,
214
-            $this
215
-        );
216
-        // Request PayPal token.
217
-        $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment);
218
-        $token_rstatus = $this->_ppExpress_check_response($token_request_response);
219
-        $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args']))
220
-            ? $token_rstatus['args']
221
-            : array();
222
-        if ($token_rstatus['status']) {
223
-            // We got the Token so we may continue with the payment and redirect the client.
224
-            $payment->set_details($response_args);
225
-            $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
226
-            $payment->set_redirect_url(
227
-                $gateway_url
228
-                . '/checkoutnow?useraction=commit&cmd=_express-checkout&token='
229
-                . $response_args['TOKEN']
230
-            );
231
-        } else {
232
-            if (isset($response_args['L_ERRORCODE'])) {
233
-                $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']);
234
-            } else {
235
-                $payment->set_gateway_response(
236
-                    esc_html__(
237
-                        'Error occurred while trying to setup the Express Checkout.',
238
-                        'event_espresso'
239
-                    )
240
-                );
241
-            }
242
-            $payment->set_details($response_args);
243
-            $payment->set_status($this->_pay_model->failed_status());
244
-        }
245
-        return $payment;
246
-    }
247
-
248
-
249
-
250
-    /**
251
-     * @param array           $update_info {
252
-     * @type string           $gateway_txn_id
253
-     * @type string status an EEMI_Payment status
254
-     *                                     }
255
-     * @param EEI_Transaction $transaction
256
-     * @return EEI_Payment
257
-     */
258
-    public function handle_payment_update($update_info, $transaction)
259
-    {
260
-        $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null;
261
-        if ($payment instanceof EEI_Payment) {
262
-            $this->log(array('Return from Authorization' => $update_info), $payment);
263
-            $transaction = $payment->transaction();
264
-            if (! $transaction instanceof EEI_Transaction) {
265
-                $payment->set_gateway_response(
266
-                    esc_html__(
267
-                        'Could not process this payment because it has no associated transaction.',
268
-                        'event_espresso'
269
-                    )
270
-                );
271
-                $payment->set_status($this->_pay_model->failed_status());
272
-                return $payment;
273
-            }
274
-            $primary_registrant = $transaction->primary_registration();
275
-            $payment_details = $payment->details();
276
-            // Check if we still have the token.
277
-            if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
278
-                $payment->set_status($this->_pay_model->failed_status());
279
-                return $payment;
280
-            }
281
-            $cdetails_request_dtls = array(
282
-                'METHOD' => 'GetExpressCheckoutDetails',
283
-                'TOKEN'  => $payment_details['TOKEN'],
284
-            );
285
-            // Request Customer Details.
286
-            $cdetails_request_response = $this->_ppExpress_request(
287
-                $cdetails_request_dtls,
288
-                'Customer Details',
289
-                $payment
290
-            );
291
-            $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response);
292
-            $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']))
293
-                ? $cdetails_rstatus['args']
294
-                : array();
295
-            if ($cdetails_rstatus['status']) {
296
-                // We got the PayerID so now we can Complete the transaction.
297
-                $docheckout_request_dtls = array(
298
-                    'METHOD'                         => 'DoExpressCheckoutPayment',
299
-                    'PAYERID'                        => $cdata_response_args['PAYERID'],
300
-                    'TOKEN'                          => $payment_details['TOKEN'],
301
-                    'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
302
-                    'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
303
-                    'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
304
-                );
305
-                 // Include itemized list.
306
-                $itemized_list = $this->itemize_list(
307
-                    $payment,
308
-                    $transaction,
309
-                    $cdata_response_args
310
-                );
311
-                $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list);
312
-                // Payment Checkout/Capture.
313
-                $docheckout_request_response = $this->_ppExpress_request(
314
-                    $docheckout_request_dtls,
315
-                    'Do Payment',
316
-                    $payment
317
-                );
318
-                $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response);
319
-                $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']))
320
-                    ? $docheckout_rstatus['args']
321
-                    : array();
322
-                if ($docheckout_rstatus['status']) {
323
-                    // All is well, payment approved.
324
-                    $primary_registration_code = $primary_registrant instanceof EE_Registration ?
325
-                        $primary_registrant->reg_code()
326
-                        : '';
327
-                    $payment->set_extra_accntng($primary_registration_code);
328
-                    $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT'])
329
-                        ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT']
330
-                        : 0);
331
-                    $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'])
332
-                        ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']
333
-                        : null);
334
-                    $payment->set_details($cdata_response_args);
335
-                    $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK'])
336
-                        ? $docheckout_response_args['PAYMENTINFO_0_ACK']
337
-                        : '');
338
-                    $payment->set_status($this->_pay_model->approved_status());
339
-                } else {
340
-                    if (isset($docheckout_response_args['L_ERRORCODE'])) {
341
-                        $payment->set_gateway_response(
342
-                            $docheckout_response_args['L_ERRORCODE']
343
-                            . '; '
344
-                            . $docheckout_response_args['L_SHORTMESSAGE']
345
-                        );
346
-                    } else {
347
-                        $payment->set_gateway_response(
348
-                            esc_html__(
349
-                                'Error occurred while trying to Capture the funds.',
350
-                                'event_espresso'
351
-                            )
352
-                        );
353
-                    }
354
-                    $payment->set_details($docheckout_response_args);
355
-                    $payment->set_status($this->_pay_model->declined_status());
356
-                }
357
-            } else {
358
-                if (isset($cdata_response_args['L_ERRORCODE'])) {
359
-                    $payment->set_gateway_response(
360
-                        $cdata_response_args['L_ERRORCODE']
361
-                        . '; '
362
-                        . $cdata_response_args['L_SHORTMESSAGE']
363
-                    );
364
-                } else {
365
-                    $payment->set_gateway_response(
366
-                        esc_html__(
367
-                            'Error occurred while trying to get payment Details from PayPal.',
368
-                            'event_espresso'
369
-                        )
370
-                    );
371
-                }
372
-                $payment->set_details($cdata_response_args);
373
-                $payment->set_status($this->_pay_model->failed_status());
374
-            }
375
-        } else {
376
-            $payment->set_gateway_response(
377
-                esc_html__(
378
-                    'Error occurred while trying to process the payment.',
379
-                    'event_espresso'
380
-                )
381
-            );
382
-            $payment->set_status($this->_pay_model->failed_status());
383
-        }
384
-        return $payment;
385
-    }
386
-
387
-
388
-
389
-    /**
390
-     *  Make a list of items that are in the giver transaction.
391
-     *
392
-     * @param EEI_Payment     $payment
393
-     * @param EEI_Transaction $transaction
394
-     * @param array           $request_response_args Data from a previous communication with PP.
395
-     * @return array
396
-     */
397
-    public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array())
398
-    {
399
-        $itemized_list = array();
400
-        $gateway_formatter = $this->_get_gateway_formatter();
401
-        // If we have data from a previous communication with PP (on this transaction) we may use that for our list...
402
-        if (! empty($request_response_args)
403
-            && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args)
404
-            && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args)
405
-        ) {
406
-            foreach ($request_response_args as $arg_key => $arg_val) {
407
-                if (strpos($arg_key, 'PAYMENTREQUEST_') !== false
408
-                    && strpos($arg_key, 'NOTIFYURL') === false
409
-                ) {
410
-                    $itemized_list[ $arg_key ] = $arg_val;
411
-                }
412
-            }
413
-            // If we got only a few Items then something is not right.
414
-            if (count($itemized_list) > 2) {
415
-                return $itemized_list;
416
-            } else {
417
-                if (WP_DEBUG) {
418
-                    throw new EE_Error(
419
-                        sprintf(
420
-                            esc_html__(
421
-                                // @codingStandardsIgnoreStart
422
-                                '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',
423
-                                // @codingStandardsIgnoreEnd
424
-                                'event_espresso'
425
-                            ),
426
-                            wp_json_encode($itemized_list)
427
-                        )
428
-                    );
429
-                }
430
-                // Reset the list and log an error, maybe allow to try and generate a new list (below).
431
-                $itemized_list = array();
432
-                $this->log(
433
-                    array(
434
-                        esc_html__(
435
-                            'Could not generate a proper item list with:',
436
-                            'event_espresso'
437
-                        ) => $request_response_args
438
-                    ),
439
-                    $payment
440
-                );
441
-            }
442
-        }
443
-        // ...otherwise we generate a new list for this transaction.
444
-        if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
445
-            $item_num = 0;
446
-            $itemized_sum = 0;
447
-            $total_line_items = $transaction->total_line_item();
448
-            // Go through each item in the list.
449
-            foreach ($total_line_items->get_items() as $line_item) {
450
-                if ($line_item instanceof EE_Line_Item) {
451
-                    // PayPal doesn't like line items with 0.00 amount, so we may skip those.
452
-                    if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) {
453
-                        continue;
454
-                    }
455
-                    $unit_price = $line_item->unit_price();
456
-                    $line_item_quantity = $line_item->quantity();
457
-                    // This is a discount.
458
-                    if ($line_item->is_percent()) {
459
-                        $unit_price = $line_item->total();
460
-                        $line_item_quantity = 1;
461
-                    }
462
-                    // Item Name.
463
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut(
464
-                        $gateway_formatter->formatLineItemName($line_item, $payment),
465
-                        0,
466
-                        127
467
-                    );
468
-                    // Item description.
469
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut(
470
-                        $gateway_formatter->formatLineItemDesc($line_item, $payment),
471
-                        0,
472
-                        127
473
-                    );
474
-                    // Cost of individual item.
475
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price);
476
-                    // Item Number.
477
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1;
478
-                    // Item quantity.
479
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity;
480
-                    // Digital item is sold.
481
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical';
482
-                    $itemized_sum += $line_item->total();
483
-                    ++$item_num;
484
-                }
485
-            }
486
-            // Item's sales S/H and tax amount.
487
-            $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total();
488
-            $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax();
489
-            $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
490
-            $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
491
-            $itemized_sum_diff_from_txn_total = round(
492
-                $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(),
493
-                2
494
-            );
495
-            // If we were not able to recognize some item like promotion, surcharge or cancellation,
496
-            // add the difference as an extra line item.
497
-            if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
498
-                // Item Name.
499
-                $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut(
500
-                    esc_html__(
501
-                        'Other (promotion/surcharge/cancellation)',
502
-                        'event_espresso'
503
-                    ),
504
-                    0,
505
-                    127
506
-                );
507
-                // Item description.
508
-                $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = '';
509
-                // Cost of individual item.
510
-                $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency(
511
-                    $itemized_sum_diff_from_txn_total
512
-                );
513
-                // Item Number.
514
-                $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1;
515
-                // Item quantity.
516
-                $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1;
517
-                // Digital item is sold.
518
-                $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical';
519
-                $item_num++;
520
-            }
521
-        } else {
522
-            // Just one Item.
523
-            // Item Name.
524
-            $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut(
525
-                $gateway_formatter->formatPartialPaymentLineItemName($payment),
526
-                0,
527
-                127
528
-            );
529
-            // Item description.
530
-            $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut(
531
-                $gateway_formatter->formatPartialPaymentLineItemDesc($payment),
532
-                0,
533
-                127
534
-            );
535
-            // Cost of individual item.
536
-            $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount());
537
-            // Item Number.
538
-            $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1;
539
-            // Item quantity.
540
-            $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1;
541
-            // Digital item is sold.
542
-            $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical';
543
-            // Item's sales S/H and tax amount.
544
-            $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount());
545
-            $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0';
546
-            $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
547
-            $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
548
-        }
549
-        return $itemized_list;
550
-    }
551
-
552
-
553
-
554
-    /**
555
-     *  Make the Express checkout request.
556
-     *
557
-     * @param array       $request_params
558
-     * @param string      $request_text
559
-     * @param EEI_Payment $payment
560
-     * @return mixed
561
-     */
562
-    public function _ppExpress_request($request_params, $request_text, $payment)
563
-    {
564
-        $request_dtls = array(
565
-            'VERSION' => '204.0',
566
-            'USER' => urlencode($this->_api_username),
567
-            'PWD' => urlencode($this->_api_password),
568
-            'SIGNATURE' => urlencode($this->_api_signature),
569
-            // EE will blow up if you change this
570
-            'BUTTONSOURCE' => 'EventEspresso_SP',
571
-        );
572
-        $dtls = array_merge($request_dtls, $request_params);
573
-        $this->_log_clean_request($dtls, $payment, $request_text . ' Request');
574
-        // Request Customer Details.
575
-        $request_response = wp_remote_post(
576
-            $this->_base_gateway_url,
577
-            array(
578
-                'method'      => 'POST',
579
-                'timeout'     => 45,
580
-                'httpversion' => '1.1',
581
-                'cookies'     => array(),
582
-                'headers'     => array(),
583
-                'body'        => http_build_query($dtls, '', '&'),
584
-            )
585
-        );
586
-        // Log the response.
587
-        $this->log(array($request_text . ' Response' => $request_response), $payment);
588
-        return $request_response;
589
-    }
590
-
591
-
592
-
593
-    /**
594
-     *  Check the response status.
595
-     *
596
-     * @param mixed $request_response
597
-     * @return array
598
-     */
599
-    public function _ppExpress_check_response($request_response)
600
-    {
601
-        if (is_wp_error($request_response) || empty($request_response['body'])) {
602
-            // If we got here then there was an error in this request.
603
-            return array('status' => false, 'args' => $request_response);
604
-        }
605
-        $response_args = array();
606
-        parse_str(urldecode($request_response['body']), $response_args);
607
-        if (! isset($response_args['ACK'])) {
608
-            return array('status' => false, 'args' => $request_response);
609
-        }
610
-        if ((
611
-                isset($response_args['PAYERID'])
612
-                || isset($response_args['TOKEN'])
613
-                || isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
614
-                || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
615
-            )
616
-            && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true)
617
-        ) {
618
-            // Response status OK, return response parameters for further processing.
619
-            return array('status' => true, 'args' => $response_args);
620
-        }
621
-        $errors = $this->_get_errors($response_args);
622
-        return array('status' => false, 'args' => $errors);
623
-    }
624
-
625
-
626
-
627
-    /**
628
-     *  Log a "Cleared" request.
629
-     *
630
-     * @param array       $request
631
-     * @param EEI_Payment $payment
632
-     * @param string      $info
633
-     * @return void
634
-     */
635
-    private function _log_clean_request($request, $payment, $info)
636
-    {
637
-        $cleaned_request_data = $request;
638
-        unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']);
639
-        $this->log(array($info => $cleaned_request_data), $payment);
640
-    }
641
-
642
-
643
-
644
-    /**
645
-     *  Get error from the response data.
646
-     *
647
-     * @param array $data_array
648
-     * @return array
649
-     */
650
-    private function _get_errors($data_array)
651
-    {
652
-        $errors = array();
653
-        $n = 0;
654
-        while (isset($data_array[ "L_ERRORCODE{$n}" ])) {
655
-            $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ])
656
-                ? $data_array[ "L_ERRORCODE{$n}" ]
657
-                : '';
658
-            $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ])
659
-                ? $data_array[ "L_SEVERITYCODE{$n}" ]
660
-                : '';
661
-            $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ])
662
-                ? $data_array[ "L_SHORTMESSAGE{$n}" ]
663
-                : '';
664
-            $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ])
665
-                ? $data_array[ "L_LONGMESSAGE{$n}" ]
666
-                : '';
667
-            if ($n === 0) {
668
-                $errors = array(
669
-                    'L_ERRORCODE'    => $l_error_code,
670
-                    'L_SHORTMESSAGE' => $l_short_message,
671
-                    'L_LONGMESSAGE'  => $l_long_message,
672
-                    'L_SEVERITYCODE' => $l_severity_code,
673
-                );
674
-            } else {
675
-                $errors['L_ERRORCODE'] .= ', ' . $l_error_code;
676
-                $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
677
-                $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
678
-                $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
679
-            }
680
-            $n++;
681
-        }
682
-        return $errors;
683
-    }
30
+	/**
31
+	 * Merchant API Username.
32
+	 *
33
+	 * @var string
34
+	 */
35
+	protected $_api_username;
36
+
37
+	/**
38
+	 * Merchant API Password.
39
+	 *
40
+	 * @var string
41
+	 */
42
+	protected $_api_password;
43
+
44
+	/**
45
+	 * API Signature.
46
+	 *
47
+	 * @var string
48
+	 */
49
+	protected $_api_signature;
50
+
51
+	/**
52
+	 * Request Shipping address on PP checkout page.
53
+	 *
54
+	 * @var string
55
+	 */
56
+	protected $_request_shipping_addr;
57
+
58
+	/**
59
+	 * Business/personal logo.
60
+	 *
61
+	 * @var string
62
+	 */
63
+	protected $_image_url;
64
+
65
+	/**
66
+	 * gateway URL variable
67
+	 *
68
+	 * @var string
69
+	 */
70
+	protected $_base_gateway_url = '';
71
+
72
+
73
+
74
+	/**
75
+	 * EEG_Paypal_Express constructor.
76
+	 */
77
+	public function __construct()
78
+	{
79
+		$this->_currencies_supported = array(
80
+			'USD',
81
+			'AUD',
82
+			'BRL',
83
+			'CAD',
84
+			'CZK',
85
+			'DKK',
86
+			'EUR',
87
+			'HKD',
88
+			'HUF',
89
+			'ILS',
90
+			'JPY',
91
+			'MYR',
92
+			'MXN',
93
+			'NOK',
94
+			'NZD',
95
+			'PHP',
96
+			'PLN',
97
+			'GBP',
98
+			'RUB',
99
+			'SGD',
100
+			'SEK',
101
+			'CHF',
102
+			'TWD',
103
+			'THB',
104
+			'TRY',
105
+			'INR',
106
+		);
107
+		parent::__construct();
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * Sets the gateway URL variable based on whether debug mode is enabled or not.
114
+	 *
115
+	 * @param array $settings_array
116
+	 */
117
+	public function set_settings($settings_array)
118
+	{
119
+		parent::set_settings($settings_array);
120
+		// Redirect URL.
121
+		$this->_base_gateway_url = $this->_debug_mode
122
+			? 'https://api-3t.sandbox.paypal.com/nvp'
123
+			: 'https://api-3t.paypal.com/nvp';
124
+	}
125
+
126
+
127
+
128
+	/**
129
+	 * @param EEI_Payment $payment
130
+	 * @param array       $billing_info
131
+	 * @param string      $return_url
132
+	 * @param string      $notify_url
133
+	 * @param string      $cancel_url
134
+	 * @return \EE_Payment|\EEI_Payment
135
+	 * @throws \EE_Error
136
+	 */
137
+	public function set_redirection_info(
138
+		$payment,
139
+		$billing_info = array(),
140
+		$return_url = null,
141
+		$notify_url = null,
142
+		$cancel_url = null
143
+	) {
144
+		if (! $payment instanceof EEI_Payment) {
145
+			$payment->set_gateway_response(
146
+				esc_html__(
147
+					'Error. No associated payment was found.',
148
+					'event_espresso'
149
+				)
150
+			);
151
+			$payment->set_status($this->_pay_model->failed_status());
152
+			return $payment;
153
+		}
154
+		$transaction = $payment->transaction();
155
+		if (! $transaction instanceof EEI_Transaction) {
156
+			$payment->set_gateway_response(
157
+				esc_html__(
158
+					'Could not process this payment because it has no associated transaction.',
159
+					'event_espresso'
160
+				)
161
+			);
162
+			$payment->set_status($this->_pay_model->failed_status());
163
+			return $payment;
164
+		}
165
+		$gateway_formatter = $this->_get_gateway_formatter();
166
+		$order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127);
167
+		$primary_registration = $transaction->primary_registration();
168
+		$primary_attendee = $primary_registration instanceof EE_Registration
169
+			? $primary_registration->attendee()
170
+			: false;
171
+		$locale = explode('-', get_bloginfo('language'));
172
+		// Gather request parameters.
173
+		$token_request_dtls = array(
174
+			'METHOD'                         => 'SetExpressCheckout',
175
+			'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
176
+			'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
177
+			'PAYMENTREQUEST_0_DESC'          => $order_description,
178
+			'RETURNURL'                      => $return_url,
179
+			'CANCELURL'                      => $cancel_url,
180
+			'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
181
+			// Buyer does not need to create a PayPal account to check out.
182
+			// This is referred to as PayPal Account Optional.
183
+			'SOLUTIONTYPE'                   => 'Sole',
184
+			// Locale of the pages displayed by PayPal during Express Checkout.
185
+			'LOCALECODE'                     => $locale[1]
186
+		);
187
+		// Show itemized list.
188
+		$itemized_list = $this->itemize_list($payment, $transaction);
189
+		$token_request_dtls = array_merge($token_request_dtls, $itemized_list);
190
+		// Automatically filling out shipping and contact information.
191
+		if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) {
192
+			// If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
193
+			$token_request_dtls['NOSHIPPING'] = '2';
194
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address();
195
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2();
196
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city();
197
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev();
198
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID();
199
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
200
+			$token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
201
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
202
+		} elseif (! $this->_request_shipping_addr) {
203
+			// Do not request shipping details on the PP Checkout page.
204
+			$token_request_dtls['NOSHIPPING'] = '1';
205
+			$token_request_dtls['REQCONFIRMSHIPPING'] = '0';
206
+		}
207
+		// Used a business/personal logo on the PayPal page.
208
+		if (! empty($this->_image_url)) {
209
+			$token_request_dtls['LOGOIMG'] = $this->_image_url;
210
+		}
211
+		$token_request_dtls = apply_filters(
212
+			'FHEE__EEG_Paypal_Express__set_redirection_info__arguments',
213
+			$token_request_dtls,
214
+			$this
215
+		);
216
+		// Request PayPal token.
217
+		$token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment);
218
+		$token_rstatus = $this->_ppExpress_check_response($token_request_response);
219
+		$response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args']))
220
+			? $token_rstatus['args']
221
+			: array();
222
+		if ($token_rstatus['status']) {
223
+			// We got the Token so we may continue with the payment and redirect the client.
224
+			$payment->set_details($response_args);
225
+			$gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
226
+			$payment->set_redirect_url(
227
+				$gateway_url
228
+				. '/checkoutnow?useraction=commit&cmd=_express-checkout&token='
229
+				. $response_args['TOKEN']
230
+			);
231
+		} else {
232
+			if (isset($response_args['L_ERRORCODE'])) {
233
+				$payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']);
234
+			} else {
235
+				$payment->set_gateway_response(
236
+					esc_html__(
237
+						'Error occurred while trying to setup the Express Checkout.',
238
+						'event_espresso'
239
+					)
240
+				);
241
+			}
242
+			$payment->set_details($response_args);
243
+			$payment->set_status($this->_pay_model->failed_status());
244
+		}
245
+		return $payment;
246
+	}
247
+
248
+
249
+
250
+	/**
251
+	 * @param array           $update_info {
252
+	 * @type string           $gateway_txn_id
253
+	 * @type string status an EEMI_Payment status
254
+	 *                                     }
255
+	 * @param EEI_Transaction $transaction
256
+	 * @return EEI_Payment
257
+	 */
258
+	public function handle_payment_update($update_info, $transaction)
259
+	{
260
+		$payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null;
261
+		if ($payment instanceof EEI_Payment) {
262
+			$this->log(array('Return from Authorization' => $update_info), $payment);
263
+			$transaction = $payment->transaction();
264
+			if (! $transaction instanceof EEI_Transaction) {
265
+				$payment->set_gateway_response(
266
+					esc_html__(
267
+						'Could not process this payment because it has no associated transaction.',
268
+						'event_espresso'
269
+					)
270
+				);
271
+				$payment->set_status($this->_pay_model->failed_status());
272
+				return $payment;
273
+			}
274
+			$primary_registrant = $transaction->primary_registration();
275
+			$payment_details = $payment->details();
276
+			// Check if we still have the token.
277
+			if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
278
+				$payment->set_status($this->_pay_model->failed_status());
279
+				return $payment;
280
+			}
281
+			$cdetails_request_dtls = array(
282
+				'METHOD' => 'GetExpressCheckoutDetails',
283
+				'TOKEN'  => $payment_details['TOKEN'],
284
+			);
285
+			// Request Customer Details.
286
+			$cdetails_request_response = $this->_ppExpress_request(
287
+				$cdetails_request_dtls,
288
+				'Customer Details',
289
+				$payment
290
+			);
291
+			$cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response);
292
+			$cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']))
293
+				? $cdetails_rstatus['args']
294
+				: array();
295
+			if ($cdetails_rstatus['status']) {
296
+				// We got the PayerID so now we can Complete the transaction.
297
+				$docheckout_request_dtls = array(
298
+					'METHOD'                         => 'DoExpressCheckoutPayment',
299
+					'PAYERID'                        => $cdata_response_args['PAYERID'],
300
+					'TOKEN'                          => $payment_details['TOKEN'],
301
+					'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
302
+					'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
303
+					'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
304
+				);
305
+				 // Include itemized list.
306
+				$itemized_list = $this->itemize_list(
307
+					$payment,
308
+					$transaction,
309
+					$cdata_response_args
310
+				);
311
+				$docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list);
312
+				// Payment Checkout/Capture.
313
+				$docheckout_request_response = $this->_ppExpress_request(
314
+					$docheckout_request_dtls,
315
+					'Do Payment',
316
+					$payment
317
+				);
318
+				$docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response);
319
+				$docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']))
320
+					? $docheckout_rstatus['args']
321
+					: array();
322
+				if ($docheckout_rstatus['status']) {
323
+					// All is well, payment approved.
324
+					$primary_registration_code = $primary_registrant instanceof EE_Registration ?
325
+						$primary_registrant->reg_code()
326
+						: '';
327
+					$payment->set_extra_accntng($primary_registration_code);
328
+					$payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT'])
329
+						? (float) $docheckout_response_args['PAYMENTINFO_0_AMT']
330
+						: 0);
331
+					$payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'])
332
+						? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']
333
+						: null);
334
+					$payment->set_details($cdata_response_args);
335
+					$payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK'])
336
+						? $docheckout_response_args['PAYMENTINFO_0_ACK']
337
+						: '');
338
+					$payment->set_status($this->_pay_model->approved_status());
339
+				} else {
340
+					if (isset($docheckout_response_args['L_ERRORCODE'])) {
341
+						$payment->set_gateway_response(
342
+							$docheckout_response_args['L_ERRORCODE']
343
+							. '; '
344
+							. $docheckout_response_args['L_SHORTMESSAGE']
345
+						);
346
+					} else {
347
+						$payment->set_gateway_response(
348
+							esc_html__(
349
+								'Error occurred while trying to Capture the funds.',
350
+								'event_espresso'
351
+							)
352
+						);
353
+					}
354
+					$payment->set_details($docheckout_response_args);
355
+					$payment->set_status($this->_pay_model->declined_status());
356
+				}
357
+			} else {
358
+				if (isset($cdata_response_args['L_ERRORCODE'])) {
359
+					$payment->set_gateway_response(
360
+						$cdata_response_args['L_ERRORCODE']
361
+						. '; '
362
+						. $cdata_response_args['L_SHORTMESSAGE']
363
+					);
364
+				} else {
365
+					$payment->set_gateway_response(
366
+						esc_html__(
367
+							'Error occurred while trying to get payment Details from PayPal.',
368
+							'event_espresso'
369
+						)
370
+					);
371
+				}
372
+				$payment->set_details($cdata_response_args);
373
+				$payment->set_status($this->_pay_model->failed_status());
374
+			}
375
+		} else {
376
+			$payment->set_gateway_response(
377
+				esc_html__(
378
+					'Error occurred while trying to process the payment.',
379
+					'event_espresso'
380
+				)
381
+			);
382
+			$payment->set_status($this->_pay_model->failed_status());
383
+		}
384
+		return $payment;
385
+	}
386
+
387
+
388
+
389
+	/**
390
+	 *  Make a list of items that are in the giver transaction.
391
+	 *
392
+	 * @param EEI_Payment     $payment
393
+	 * @param EEI_Transaction $transaction
394
+	 * @param array           $request_response_args Data from a previous communication with PP.
395
+	 * @return array
396
+	 */
397
+	public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array())
398
+	{
399
+		$itemized_list = array();
400
+		$gateway_formatter = $this->_get_gateway_formatter();
401
+		// If we have data from a previous communication with PP (on this transaction) we may use that for our list...
402
+		if (! empty($request_response_args)
403
+			&& array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args)
404
+			&& array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args)
405
+		) {
406
+			foreach ($request_response_args as $arg_key => $arg_val) {
407
+				if (strpos($arg_key, 'PAYMENTREQUEST_') !== false
408
+					&& strpos($arg_key, 'NOTIFYURL') === false
409
+				) {
410
+					$itemized_list[ $arg_key ] = $arg_val;
411
+				}
412
+			}
413
+			// If we got only a few Items then something is not right.
414
+			if (count($itemized_list) > 2) {
415
+				return $itemized_list;
416
+			} else {
417
+				if (WP_DEBUG) {
418
+					throw new EE_Error(
419
+						sprintf(
420
+							esc_html__(
421
+								// @codingStandardsIgnoreStart
422
+								'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',
423
+								// @codingStandardsIgnoreEnd
424
+								'event_espresso'
425
+							),
426
+							wp_json_encode($itemized_list)
427
+						)
428
+					);
429
+				}
430
+				// Reset the list and log an error, maybe allow to try and generate a new list (below).
431
+				$itemized_list = array();
432
+				$this->log(
433
+					array(
434
+						esc_html__(
435
+							'Could not generate a proper item list with:',
436
+							'event_espresso'
437
+						) => $request_response_args
438
+					),
439
+					$payment
440
+				);
441
+			}
442
+		}
443
+		// ...otherwise we generate a new list for this transaction.
444
+		if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
445
+			$item_num = 0;
446
+			$itemized_sum = 0;
447
+			$total_line_items = $transaction->total_line_item();
448
+			// Go through each item in the list.
449
+			foreach ($total_line_items->get_items() as $line_item) {
450
+				if ($line_item instanceof EE_Line_Item) {
451
+					// PayPal doesn't like line items with 0.00 amount, so we may skip those.
452
+					if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) {
453
+						continue;
454
+					}
455
+					$unit_price = $line_item->unit_price();
456
+					$line_item_quantity = $line_item->quantity();
457
+					// This is a discount.
458
+					if ($line_item->is_percent()) {
459
+						$unit_price = $line_item->total();
460
+						$line_item_quantity = 1;
461
+					}
462
+					// Item Name.
463
+					$itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut(
464
+						$gateway_formatter->formatLineItemName($line_item, $payment),
465
+						0,
466
+						127
467
+					);
468
+					// Item description.
469
+					$itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut(
470
+						$gateway_formatter->formatLineItemDesc($line_item, $payment),
471
+						0,
472
+						127
473
+					);
474
+					// Cost of individual item.
475
+					$itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price);
476
+					// Item Number.
477
+					$itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1;
478
+					// Item quantity.
479
+					$itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity;
480
+					// Digital item is sold.
481
+					$itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical';
482
+					$itemized_sum += $line_item->total();
483
+					++$item_num;
484
+				}
485
+			}
486
+			// Item's sales S/H and tax amount.
487
+			$itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total();
488
+			$itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax();
489
+			$itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
490
+			$itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
491
+			$itemized_sum_diff_from_txn_total = round(
492
+				$transaction->total() - $itemized_sum - $total_line_items->get_total_tax(),
493
+				2
494
+			);
495
+			// If we were not able to recognize some item like promotion, surcharge or cancellation,
496
+			// add the difference as an extra line item.
497
+			if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
498
+				// Item Name.
499
+				$itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut(
500
+					esc_html__(
501
+						'Other (promotion/surcharge/cancellation)',
502
+						'event_espresso'
503
+					),
504
+					0,
505
+					127
506
+				);
507
+				// Item description.
508
+				$itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = '';
509
+				// Cost of individual item.
510
+				$itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency(
511
+					$itemized_sum_diff_from_txn_total
512
+				);
513
+				// Item Number.
514
+				$itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1;
515
+				// Item quantity.
516
+				$itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1;
517
+				// Digital item is sold.
518
+				$itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical';
519
+				$item_num++;
520
+			}
521
+		} else {
522
+			// Just one Item.
523
+			// Item Name.
524
+			$itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut(
525
+				$gateway_formatter->formatPartialPaymentLineItemName($payment),
526
+				0,
527
+				127
528
+			);
529
+			// Item description.
530
+			$itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut(
531
+				$gateway_formatter->formatPartialPaymentLineItemDesc($payment),
532
+				0,
533
+				127
534
+			);
535
+			// Cost of individual item.
536
+			$itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount());
537
+			// Item Number.
538
+			$itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1;
539
+			// Item quantity.
540
+			$itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1;
541
+			// Digital item is sold.
542
+			$itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical';
543
+			// Item's sales S/H and tax amount.
544
+			$itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount());
545
+			$itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0';
546
+			$itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
547
+			$itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
548
+		}
549
+		return $itemized_list;
550
+	}
551
+
552
+
553
+
554
+	/**
555
+	 *  Make the Express checkout request.
556
+	 *
557
+	 * @param array       $request_params
558
+	 * @param string      $request_text
559
+	 * @param EEI_Payment $payment
560
+	 * @return mixed
561
+	 */
562
+	public function _ppExpress_request($request_params, $request_text, $payment)
563
+	{
564
+		$request_dtls = array(
565
+			'VERSION' => '204.0',
566
+			'USER' => urlencode($this->_api_username),
567
+			'PWD' => urlencode($this->_api_password),
568
+			'SIGNATURE' => urlencode($this->_api_signature),
569
+			// EE will blow up if you change this
570
+			'BUTTONSOURCE' => 'EventEspresso_SP',
571
+		);
572
+		$dtls = array_merge($request_dtls, $request_params);
573
+		$this->_log_clean_request($dtls, $payment, $request_text . ' Request');
574
+		// Request Customer Details.
575
+		$request_response = wp_remote_post(
576
+			$this->_base_gateway_url,
577
+			array(
578
+				'method'      => 'POST',
579
+				'timeout'     => 45,
580
+				'httpversion' => '1.1',
581
+				'cookies'     => array(),
582
+				'headers'     => array(),
583
+				'body'        => http_build_query($dtls, '', '&'),
584
+			)
585
+		);
586
+		// Log the response.
587
+		$this->log(array($request_text . ' Response' => $request_response), $payment);
588
+		return $request_response;
589
+	}
590
+
591
+
592
+
593
+	/**
594
+	 *  Check the response status.
595
+	 *
596
+	 * @param mixed $request_response
597
+	 * @return array
598
+	 */
599
+	public function _ppExpress_check_response($request_response)
600
+	{
601
+		if (is_wp_error($request_response) || empty($request_response['body'])) {
602
+			// If we got here then there was an error in this request.
603
+			return array('status' => false, 'args' => $request_response);
604
+		}
605
+		$response_args = array();
606
+		parse_str(urldecode($request_response['body']), $response_args);
607
+		if (! isset($response_args['ACK'])) {
608
+			return array('status' => false, 'args' => $request_response);
609
+		}
610
+		if ((
611
+				isset($response_args['PAYERID'])
612
+				|| isset($response_args['TOKEN'])
613
+				|| isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
614
+				|| (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
615
+			)
616
+			&& in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true)
617
+		) {
618
+			// Response status OK, return response parameters for further processing.
619
+			return array('status' => true, 'args' => $response_args);
620
+		}
621
+		$errors = $this->_get_errors($response_args);
622
+		return array('status' => false, 'args' => $errors);
623
+	}
624
+
625
+
626
+
627
+	/**
628
+	 *  Log a "Cleared" request.
629
+	 *
630
+	 * @param array       $request
631
+	 * @param EEI_Payment $payment
632
+	 * @param string      $info
633
+	 * @return void
634
+	 */
635
+	private function _log_clean_request($request, $payment, $info)
636
+	{
637
+		$cleaned_request_data = $request;
638
+		unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']);
639
+		$this->log(array($info => $cleaned_request_data), $payment);
640
+	}
641
+
642
+
643
+
644
+	/**
645
+	 *  Get error from the response data.
646
+	 *
647
+	 * @param array $data_array
648
+	 * @return array
649
+	 */
650
+	private function _get_errors($data_array)
651
+	{
652
+		$errors = array();
653
+		$n = 0;
654
+		while (isset($data_array[ "L_ERRORCODE{$n}" ])) {
655
+			$l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ])
656
+				? $data_array[ "L_ERRORCODE{$n}" ]
657
+				: '';
658
+			$l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ])
659
+				? $data_array[ "L_SEVERITYCODE{$n}" ]
660
+				: '';
661
+			$l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ])
662
+				? $data_array[ "L_SHORTMESSAGE{$n}" ]
663
+				: '';
664
+			$l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ])
665
+				? $data_array[ "L_LONGMESSAGE{$n}" ]
666
+				: '';
667
+			if ($n === 0) {
668
+				$errors = array(
669
+					'L_ERRORCODE'    => $l_error_code,
670
+					'L_SHORTMESSAGE' => $l_short_message,
671
+					'L_LONGMESSAGE'  => $l_long_message,
672
+					'L_SEVERITYCODE' => $l_severity_code,
673
+				);
674
+			} else {
675
+				$errors['L_ERRORCODE'] .= ', ' . $l_error_code;
676
+				$errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
677
+				$errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
678
+				$errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
679
+			}
680
+			$n++;
681
+		}
682
+		return $errors;
683
+	}
684 684
 }
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * ----------------------------------------------
11 11
  */
12 12
 // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP
13
-if (! function_exists('mb_strcut')) {
13
+if ( ! function_exists('mb_strcut')) {
14 14
     /**
15 15
      * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
16 16
      * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
         $notify_url = null,
142 142
         $cancel_url = null
143 143
     ) {
144
-        if (! $payment instanceof EEI_Payment) {
144
+        if ( ! $payment instanceof EEI_Payment) {
145 145
             $payment->set_gateway_response(
146 146
                 esc_html__(
147 147
                     'Error. No associated payment was found.',
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
             return $payment;
153 153
         }
154 154
         $transaction = $payment->transaction();
155
-        if (! $transaction instanceof EEI_Transaction) {
155
+        if ( ! $transaction instanceof EEI_Transaction) {
156 156
             $payment->set_gateway_response(
157 157
                 esc_html__(
158 158
                     'Could not process this payment because it has no associated transaction.',
@@ -199,13 +199,13 @@  discard block
 block discarded – undo
199 199
             $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
200 200
             $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
201 201
             $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
202
-        } elseif (! $this->_request_shipping_addr) {
202
+        } elseif ( ! $this->_request_shipping_addr) {
203 203
             // Do not request shipping details on the PP Checkout page.
204 204
             $token_request_dtls['NOSHIPPING'] = '1';
205 205
             $token_request_dtls['REQCONFIRMSHIPPING'] = '0';
206 206
         }
207 207
         // Used a business/personal logo on the PayPal page.
208
-        if (! empty($this->_image_url)) {
208
+        if ( ! empty($this->_image_url)) {
209 209
             $token_request_dtls['LOGOIMG'] = $this->_image_url;
210 210
         }
211 211
         $token_request_dtls = apply_filters(
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
             );
231 231
         } else {
232 232
             if (isset($response_args['L_ERRORCODE'])) {
233
-                $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']);
233
+                $payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']);
234 234
             } else {
235 235
                 $payment->set_gateway_response(
236 236
                     esc_html__(
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
         if ($payment instanceof EEI_Payment) {
262 262
             $this->log(array('Return from Authorization' => $update_info), $payment);
263 263
             $transaction = $payment->transaction();
264
-            if (! $transaction instanceof EEI_Transaction) {
264
+            if ( ! $transaction instanceof EEI_Transaction) {
265 265
                 $payment->set_gateway_response(
266 266
                     esc_html__(
267 267
                         'Could not process this payment because it has no associated transaction.',
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
             $primary_registrant = $transaction->primary_registration();
275 275
             $payment_details = $payment->details();
276 276
             // Check if we still have the token.
277
-            if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
277
+            if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
278 278
                 $payment->set_status($this->_pay_model->failed_status());
279 279
                 return $payment;
280 280
             }
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
         $itemized_list = array();
400 400
         $gateway_formatter = $this->_get_gateway_formatter();
401 401
         // If we have data from a previous communication with PP (on this transaction) we may use that for our list...
402
-        if (! empty($request_response_args)
402
+        if ( ! empty($request_response_args)
403 403
             && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args)
404 404
             && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args)
405 405
         ) {
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
                 if (strpos($arg_key, 'PAYMENTREQUEST_') !== false
408 408
                     && strpos($arg_key, 'NOTIFYURL') === false
409 409
                 ) {
410
-                    $itemized_list[ $arg_key ] = $arg_val;
410
+                    $itemized_list[$arg_key] = $arg_val;
411 411
                 }
412 412
             }
413 413
             // If we got only a few Items then something is not right.
@@ -460,25 +460,25 @@  discard block
 block discarded – undo
460 460
                         $line_item_quantity = 1;
461 461
                     }
462 462
                     // Item Name.
463
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut(
463
+                    $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut(
464 464
                         $gateway_formatter->formatLineItemName($line_item, $payment),
465 465
                         0,
466 466
                         127
467 467
                     );
468 468
                     // Item description.
469
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut(
469
+                    $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = mb_strcut(
470 470
                         $gateway_formatter->formatLineItemDesc($line_item, $payment),
471 471
                         0,
472 472
                         127
473 473
                     );
474 474
                     // Cost of individual item.
475
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price);
475
+                    $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $gateway_formatter->formatCurrency($unit_price);
476 476
                     // Item Number.
477
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1;
477
+                    $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
478 478
                     // Item quantity.
479
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity;
479
+                    $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = $line_item_quantity;
480 480
                     // Digital item is sold.
481
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical';
481
+                    $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical';
482 482
                     $itemized_sum += $line_item->total();
483 483
                     ++$item_num;
484 484
                 }
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
             // add the difference as an extra line item.
497 497
             if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
498 498
                 // Item Name.
499
-                $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut(
499
+                $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut(
500 500
                     esc_html__(
501 501
                         'Other (promotion/surcharge/cancellation)',
502 502
                         'event_espresso'
@@ -505,17 +505,17 @@  discard block
 block discarded – undo
505 505
                     127
506 506
                 );
507 507
                 // Item description.
508
-                $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = '';
508
+                $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = '';
509 509
                 // Cost of individual item.
510
-                $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency(
510
+                $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $gateway_formatter->formatCurrency(
511 511
                     $itemized_sum_diff_from_txn_total
512 512
                 );
513 513
                 // Item Number.
514
-                $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1;
514
+                $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
515 515
                 // Item quantity.
516
-                $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1;
516
+                $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1;
517 517
                 // Digital item is sold.
518
-                $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical';
518
+                $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical';
519 519
                 $item_num++;
520 520
             }
521 521
         } else {
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
             'BUTTONSOURCE' => 'EventEspresso_SP',
571 571
         );
572 572
         $dtls = array_merge($request_dtls, $request_params);
573
-        $this->_log_clean_request($dtls, $payment, $request_text . ' Request');
573
+        $this->_log_clean_request($dtls, $payment, $request_text.' Request');
574 574
         // Request Customer Details.
575 575
         $request_response = wp_remote_post(
576 576
             $this->_base_gateway_url,
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
             )
585 585
         );
586 586
         // Log the response.
587
-        $this->log(array($request_text . ' Response' => $request_response), $payment);
587
+        $this->log(array($request_text.' Response' => $request_response), $payment);
588 588
         return $request_response;
589 589
     }
590 590
 
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
         }
605 605
         $response_args = array();
606 606
         parse_str(urldecode($request_response['body']), $response_args);
607
-        if (! isset($response_args['ACK'])) {
607
+        if ( ! isset($response_args['ACK'])) {
608 608
             return array('status' => false, 'args' => $request_response);
609 609
         }
610 610
         if ((
@@ -651,18 +651,18 @@  discard block
 block discarded – undo
651 651
     {
652 652
         $errors = array();
653 653
         $n = 0;
654
-        while (isset($data_array[ "L_ERRORCODE{$n}" ])) {
655
-            $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ])
656
-                ? $data_array[ "L_ERRORCODE{$n}" ]
654
+        while (isset($data_array["L_ERRORCODE{$n}"])) {
655
+            $l_error_code = isset($data_array["L_ERRORCODE{$n}"])
656
+                ? $data_array["L_ERRORCODE{$n}"]
657 657
                 : '';
658
-            $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ])
659
-                ? $data_array[ "L_SEVERITYCODE{$n}" ]
658
+            $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"])
659
+                ? $data_array["L_SEVERITYCODE{$n}"]
660 660
                 : '';
661
-            $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ])
662
-                ? $data_array[ "L_SHORTMESSAGE{$n}" ]
661
+            $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"])
662
+                ? $data_array["L_SHORTMESSAGE{$n}"]
663 663
                 : '';
664
-            $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ])
665
-                ? $data_array[ "L_LONGMESSAGE{$n}" ]
664
+            $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"])
665
+                ? $data_array["L_LONGMESSAGE{$n}"]
666 666
                 : '';
667 667
             if ($n === 0) {
668 668
                 $errors = array(
@@ -672,10 +672,10 @@  discard block
 block discarded – undo
672 672
                     'L_SEVERITYCODE' => $l_severity_code,
673 673
                 );
674 674
             } else {
675
-                $errors['L_ERRORCODE'] .= ', ' . $l_error_code;
676
-                $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
677
-                $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
678
-                $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
675
+                $errors['L_ERRORCODE'] .= ', '.$l_error_code;
676
+                $errors['L_SHORTMESSAGE'] .= ', '.$l_short_message;
677
+                $errors['L_LONGMESSAGE'] .= ', '.$l_long_message;
678
+                $errors['L_SEVERITYCODE'] .= ', '.$l_severity_code;
679 679
             }
680 680
             $n++;
681 681
         }
Please login to merge, or discard this patch.
form_sections/strategies/validation/EE_URL_Validation_Strategy.strategy.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -11,59 +11,59 @@
 block discarded – undo
11 11
 class EE_URL_Validation_Strategy extends EE_Validation_Strategy_Base
12 12
 {
13 13
 
14
-    /**
15
-     * @var @boolean whether we should check if the file exists or not
16
-     */
17
-    protected $check_file_exists;
14
+	/**
15
+	 * @var @boolean whether we should check if the file exists or not
16
+	 */
17
+	protected $check_file_exists;
18 18
 
19
-    /**
20
-     * @param null $validation_error_message
21
-     * @param boolean $check_file_exists
22
-     */
23
-    public function __construct($validation_error_message = null, $check_file_exists = false)
24
-    {
25
-        if (! $validation_error_message) {
26
-            $validation_error_message = __("Please enter a valid URL. Eg https://eventespresso.com", "event_espresso");
27
-        }
28
-        $this->check_file_exists = $check_file_exists;
29
-        parent::__construct($validation_error_message);
30
-    }
19
+	/**
20
+	 * @param null $validation_error_message
21
+	 * @param boolean $check_file_exists
22
+	 */
23
+	public function __construct($validation_error_message = null, $check_file_exists = false)
24
+	{
25
+		if (! $validation_error_message) {
26
+			$validation_error_message = __("Please enter a valid URL. Eg https://eventespresso.com", "event_espresso");
27
+		}
28
+		$this->check_file_exists = $check_file_exists;
29
+		parent::__construct($validation_error_message);
30
+	}
31 31
 
32 32
 
33 33
 
34
-    /**
35
-     * just checks the field isn't blank
36
-     *
37
-     * @param $normalized_value
38
-     * @return bool
39
-     * @throws \EE_Validation_Error
40
-     */
41
-    public function validate($normalized_value)
42
-    {
43
-        if ($normalized_value) {
44
-            if (filter_var($normalized_value, FILTER_VALIDATE_URL) === false) {
45
-                throw new EE_Validation_Error($this->get_validation_error_message(), 'invalid_url');
46
-            } elseif (apply_filters('FHEE__EE_URL_Validation_Strategy__validate__check_remote_file_exists', $this->check_file_exists, $this->_input)) {
47
-                if (! EEH_URL::remote_file_exists(
48
-                    $normalized_value,
49
-                    array(
50
-                            'sslverify' => false,
51
-                            'limit_response_size' => 4095,// we don't really care for a full response, but we do want headers at least. Lets just ask for a one block
52
-                        )
53
-                )) {
54
-                    throw new EE_Validation_Error(sprintf(__("That URL seems to be broken. Please enter a valid URL", "event_espresso")));
55
-                }
56
-            }
57
-        }
58
-    }
34
+	/**
35
+	 * just checks the field isn't blank
36
+	 *
37
+	 * @param $normalized_value
38
+	 * @return bool
39
+	 * @throws \EE_Validation_Error
40
+	 */
41
+	public function validate($normalized_value)
42
+	{
43
+		if ($normalized_value) {
44
+			if (filter_var($normalized_value, FILTER_VALIDATE_URL) === false) {
45
+				throw new EE_Validation_Error($this->get_validation_error_message(), 'invalid_url');
46
+			} elseif (apply_filters('FHEE__EE_URL_Validation_Strategy__validate__check_remote_file_exists', $this->check_file_exists, $this->_input)) {
47
+				if (! EEH_URL::remote_file_exists(
48
+					$normalized_value,
49
+					array(
50
+							'sslverify' => false,
51
+							'limit_response_size' => 4095,// we don't really care for a full response, but we do want headers at least. Lets just ask for a one block
52
+						)
53
+				)) {
54
+					throw new EE_Validation_Error(sprintf(__("That URL seems to be broken. Please enter a valid URL", "event_espresso")));
55
+				}
56
+			}
57
+		}
58
+	}
59 59
 
60 60
 
61 61
 
62
-    /**
63
-     * @return array
64
-     */
65
-    public function get_jquery_validation_rule_array()
66
-    {
67
-        return array( 'validUrl'=>true, 'messages' => array( 'validUrl' => $this->get_validation_error_message() ) );
68
-    }
62
+	/**
63
+	 * @return array
64
+	 */
65
+	public function get_jquery_validation_rule_array()
66
+	{
67
+		return array( 'validUrl'=>true, 'messages' => array( 'validUrl' => $this->get_validation_error_message() ) );
68
+	}
69 69
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      */
23 23
     public function __construct($validation_error_message = null, $check_file_exists = false)
24 24
     {
25
-        if (! $validation_error_message) {
25
+        if ( ! $validation_error_message) {
26 26
             $validation_error_message = __("Please enter a valid URL. Eg https://eventespresso.com", "event_espresso");
27 27
         }
28 28
         $this->check_file_exists = $check_file_exists;
@@ -44,11 +44,11 @@  discard block
 block discarded – undo
44 44
             if (filter_var($normalized_value, FILTER_VALIDATE_URL) === false) {
45 45
                 throw new EE_Validation_Error($this->get_validation_error_message(), 'invalid_url');
46 46
             } elseif (apply_filters('FHEE__EE_URL_Validation_Strategy__validate__check_remote_file_exists', $this->check_file_exists, $this->_input)) {
47
-                if (! EEH_URL::remote_file_exists(
47
+                if ( ! EEH_URL::remote_file_exists(
48 48
                     $normalized_value,
49 49
                     array(
50 50
                             'sslverify' => false,
51
-                            'limit_response_size' => 4095,// we don't really care for a full response, but we do want headers at least. Lets just ask for a one block
51
+                            'limit_response_size' => 4095, // we don't really care for a full response, but we do want headers at least. Lets just ask for a one block
52 52
                         )
53 53
                 )) {
54 54
                     throw new EE_Validation_Error(sprintf(__("That URL seems to be broken. Please enter a valid URL", "event_espresso")));
@@ -64,6 +64,6 @@  discard block
 block discarded – undo
64 64
      */
65 65
     public function get_jquery_validation_rule_array()
66 66
     {
67
-        return array( 'validUrl'=>true, 'messages' => array( 'validUrl' => $this->get_validation_error_message() ) );
67
+        return array('validUrl'=>true, 'messages' => array('validUrl' => $this->get_validation_error_message()));
68 68
     }
69 69
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Admin_File_Uploader_Input.input.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -11,21 +11,21 @@
 block discarded – undo
11 11
 class EE_Admin_File_Uploader_Input extends EE_Form_Input_Base
12 12
 {
13 13
 
14
-    /**
15
-     * @param array $input_settings
16
-     */
17
-    public function __construct($input_settings = array())
18
-    {
19
-        $this->_set_display_strategy(new EE_Admin_File_Uploader_Display_Strategy());
20
-        $this->_set_normalization_strategy(new EE_Text_Normalization());
21
-        $this->_add_validation_strategy(
22
-            new EE_URL_Validation_Strategy(
23
-                isset($input_settings['validation_error_message'])
24
-                    ? $input_settings['validation_error_message']
25
-                    : null,
26
-                true
27
-            )
28
-        );
29
-        parent::__construct($input_settings);
30
-    }
14
+	/**
15
+	 * @param array $input_settings
16
+	 */
17
+	public function __construct($input_settings = array())
18
+	{
19
+		$this->_set_display_strategy(new EE_Admin_File_Uploader_Display_Strategy());
20
+		$this->_set_normalization_strategy(new EE_Text_Normalization());
21
+		$this->_add_validation_strategy(
22
+			new EE_URL_Validation_Strategy(
23
+				isset($input_settings['validation_error_message'])
24
+					? $input_settings['validation_error_message']
25
+					: null,
26
+				true
27
+			)
28
+		);
29
+		parent::__construct($input_settings);
30
+	}
31 31
 }
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.66.rc.026');
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.66.rc.026');
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.