Completed
Branch BUG-8957-add-countries (9d990b)
by
unknown
72:59 queued 53:55
created

EEG_Paypal_Express   C

Complexity

Total Complexity 60

Size/Duplication

Total Lines 455
Duplicated Lines 9.23 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 0
Metric Value
dl 42
loc 455
rs 6.0975
c 0
b 0
f 0
wmc 60
lcom 1
cbo 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A set_settings() 0 9 2
B _ppExpress_request() 0 27 1
C _ppExpress_check_response() 0 27 12
A _log_clean_request() 0 7 1
C _get_errors() 0 28 7
D handle_payment_update() 23 77 18
F set_redirection_info() 19 152 19

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like EEG_Paypal_Express often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use EEG_Paypal_Express, and based on these observations, apply Extract Interface, too.

1
<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' )) { exit('NO direct script access allowed'); }
2
3
/**
4
 * ----------------------------------------------
5
 *
6
 * Class  EEG_Paypal_Express
7
 *
8
 * @package			Event Espresso
9
 * @subpackage		eea-paypal-express
10
 * @author			Event Espresso
11
 * @version		 	$VID:$
12
 *
13
 * ----------------------------------------------
14
 */
15
class EEG_Paypal_Express extends EE_Offsite_Gateway {
16
17
	/**
18
	 * Merchant API Username.
19
	 *  @var string
20
	 */
21
	protected $_api_username = null;
22
23
	/**
24
	 * Merchant API Password.
25
	 *  @var string
26
	 */
27
	protected $_api_password = null;
28
29
	/**
30
	 * API Signature.
31
	 *  @var string
32
	 */
33
	protected $_api_signature = null;
34
35
	/**
36
	 * Request Shipping address on PP checkout page.
37
	 *  @var string
38
	 */
39
	protected $_request_shipping_addr = null;
40
41
	/**
42
	 * Business/personal logo.
43
	 *  @var string
44
	 */
45
	protected $_image_url = null;
46
47
	/**
48
	 * All the currencies supported by this gateway.
49
	 *  @var array
50
	 */
51
	protected $_currencies_supported = array(
52
		'USD',
53
		'AUD',
54
		'BRL',
55
		'CAD',
56
		'CZK',
57
		'DKK',
58
		'EUR',
59
		'HKD',
60
		'HUF',
61
		'ILS',
62
		'JPY',
63
		'MYR',
64
		'MXN',
65
		'NOK',
66
		'NZD',
67
		'PHP',
68
		'PLN',
69
		'GBP',
70
		'RUB',
71
		'SGD',
72
		'SEK',
73
		'CHF',
74
		'TWD',
75
		'THB',
76
		'TRY'
77
	);
78
79
80
	/**
81
	 * Sets the gateway URL variable based on whether debug mode is enabled or not.
82
	 *
83
	 *  @param type $settings_array
84
	 */
85
	public function set_settings( $settings_array ) {
86
		parent::set_settings($settings_array);
87
		// Redirect URL.
88
		if ( $this->_debug_mode ) {
89
			$this->_base_gateway_url = 'https://api-3t.sandbox.paypal.com/nvp';
0 ignored issues
show
Bug introduced by
The property _base_gateway_url does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
90
		} else {
91
			$this->_base_gateway_url = 'https://api-3t.paypal.com/nvp';
92
		}
93
	}
94
95
96
	/**
97
	 *
98
	 *  @param EEI_Payment $payment
99
	 *  @param type $billing_info
100
	 *  @param type $return_url
101
	 *  @param type $cancel_url
102
	 */
103
	public function set_redirection_info( $payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL ) {
104 View Code Duplication
		if ( ! $payment instanceof EEI_Payment ) {
105
			$payment->set_gateway_response( __( 'Error. No associated payment was found.', 'event_espresso' ) );
106
			$payment->set_status( $this->_pay_model->failed_status() );
107
			return $payment;
108
		}
109
		$transaction = $payment->transaction();
110 View Code Duplication
		if ( ! $transaction instanceof EEI_Transaction ) {
111
			$payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) );
112
			$payment->set_status( $this->_pay_model->failed_status() );
113
			return $payment;
114
		}
115
		$order_description = substr( $this->_format_order_description($payment), 0, 127 );
116
		$primary_registration = $transaction->primary_registration();
117
		$primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : false;
118
		$locale = explode('-', get_bloginfo('language'));
119
120
		// Gather request parameters.
121
		$token_request_dtls = array(
122
			'METHOD' => 'SetExpressCheckout',
123
			'PAYMENTREQUEST_0_AMT' => $payment->amount(),
124
			'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(),
125
			'PAYMENTREQUEST_0_DESC' => $order_description,
126
			'RETURNURL' => $return_url,
127
			'CANCELURL' => $cancel_url,
128
			'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
129
			'SOLUTIONTYPE' => 'Sole',	// Buyer does not need to create a PayPal account to check out. This is referred to as PayPal Account Optional. 
130
			'BUTTONSOURCE' => 'EventEspresso_SP',//EE will blow up if you change this
131
			'LOCALECODE' => $locale[1]	// Locale of the pages displayed by PayPal during Express Checkout.
132
		);
133
134
		// Show itemized list.
135
		if ( EEH_Money::compare_floats( $payment->amount(), $transaction->total(), '==' ) ) {
136
			$item_num = 0;
137
			$itemized_sum = 0;
138
			$total_line_items = $transaction->total_line_item();
139
			// Go through each item in the list.
140
			foreach ( $total_line_items->get_items() as $line_item ) {
141
				if ( $line_item instanceof EE_Line_Item ) {
142
					// PayPal doesn't like line items with 0.00 amount, so we may skip those.
143
					if ( EEH_Money::compare_floats( $line_item->total(), '0.00', '==' ) ) {
144
						continue;
145
					}
146
147
					$unit_price = $line_item->unit_price();
148
					$line_item_quantity = $line_item->quantity();
149
					// This is a discount.
150
					if ( $line_item->is_percent() ) {
151
						$unit_price = $line_item->total();
152
						$line_item_quantity = 1;
153
					}
154
					// Item Name.
155
					$token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr($line_item->name(), 0, 127);
156
					// Item description.
157
					$token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr($line_item->desc(), 0, 127);
158
					// Cost of individual item.
159
					$token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $unit_price );
160
					// Item Number.
161
					$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
162
					// Item quantity.
163
					$token_request_dtls['L_PAYMENTREQUEST_0_QTY'.$item_num] = $line_item_quantity;
164
					// Digital item is sold.
165
					$token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical';
166
					$itemized_sum += $line_item->total();
167
					++$item_num;
168
				}
169
			}
170
			// Item's sales S/H and tax amount.
171
			$token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total();
172
			$token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax();
173
			$token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
174
			$token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
175
176
			$itemized_sum_diff_from_txn_total = round( $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), 2 );
177
			// If we were not able to recognize some item like promotion, surcharge or cancellation, 
178
			// add the difference as an extra line item.
179
			if ( $itemized_sum_diff_from_txn_total != 0 ) {
180
				// Item Name.
181
				$token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr( __( 'Other (promotion/surcharge/cancellation)', 'event_espresso' ), 0, 127 );
182
				// Item description.
183
				$token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr( $line_item->desc(), 0, 127 );
0 ignored issues
show
Bug introduced by
The variable $line_item seems to be defined by a foreach iteration on line 140. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
184
				// Cost of individual item.
185
				$token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $itemized_sum_diff_from_txn_total );
186
				// Item Number.
187
				$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
188
				// Item quantity.
189
				$token_request_dtls['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1;
190
				++$item_num;
191
			}
192
		} else {
193
			// Just one Item.
194
			// Item Name.
195
			$token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr( sprintf( __('Payment for %1$s', 'event_espresso'), $primary_registration->reg_code() ), 0, 127 );
196
			// Item description.
197
			$token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr( sprintf( __('Payment of %1$s for %2$s', 'event_espresso'), $payment->amount(), $primary_registration->reg_code() ), 0, 127 );
198
			// Cost of individual item.
199
			$token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency( $payment->amount() );
200
			// Item Number.
201
			$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER0'] = 1;
202
			// Item quantity.
203
			$token_request_dtls['L_PAYMENTREQUEST_0_QTY0'] = 1;
204
			// Digital item is sold.
205
			$token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical';
206
			// Item's sales S/H and tax amount.
207
			$token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency( $payment->amount() );
208
			$token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = '0';
209
			$token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
210
			$token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
211
		}
212
		// Automatically filling out shipping and contact information.
213
		if ( $this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee ) {
214
			$token_request_dtls['NOSHIPPING'] = '2';	//  If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
215
			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address();
216
			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2();
217
			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city();
218
			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev();
219
			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID();
220
			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
221
			$token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
222
			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
223
		} elseif ( ! $this->_request_shipping_addr ) {
224
			// Do not request shipping details on the PP Checkout page.
225
			$token_request_dtls['NOSHIPPING'] = '1';
226
			$token_request_dtls['REQCONFIRMSHIPPING'] = '0';
227
228
		}
229
		// Used a business/personal logo on the PayPal page.
230
		if ( ! empty($this->_image_url) ) {
231
			$token_request_dtls['LOGOIMG'] = $this->_image_url;
232
		}
233
		// Request PayPal token.
234
		$token_request_response = $this->_ppExpress_request( $token_request_dtls, 'Payment Token', $payment );
235
		$token_rstatus = $this->_ppExpress_check_response( $token_request_response );
236
		$response_args = ( isset($token_rstatus['args']) && is_array($token_rstatus['args']) ) ? $token_rstatus['args'] : array();
237
		if ( $token_rstatus['status'] ) {
238
			// We got the Token so we may continue with the payment and redirect the client.
239
			$payment->set_details( $response_args );
240
241
			$gateway_url = ( $this->_debug_mode ) ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
242
			$payment->set_redirect_url( $gateway_url . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' . $response_args['TOKEN'] );
243 View Code Duplication
		} else {
244
			if ( isset($response_args['L_ERRORCODE']) ) {
245
				$payment->set_gateway_response( $response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE'] );
246
			} else {
247
				$payment->set_gateway_response( __( 'Error occurred while trying to setup the Express Checkout.', 'event_espresso' ) );
248
			}
249
			$payment->set_details( $response_args );
250
			$payment->set_status( $this->_pay_model->failed_status() );
251
		}
252
253
		return $payment;
254
	}
255
256
257
	/**
258
	 *
259
	 *  @param array $update_info {
260
	 *	  @type string $gateway_txn_id
261
	 *	  @type string status an EEMI_Payment status
262
	 *  }
263
	 *  @param type $transaction
264
	 *  @return EEI_Payment
265
	 */
266
	public function handle_payment_update( $update_info, $transaction ) {
267
		$payment = ( $transaction instanceof EEI_Transaction ) ? $transaction->last_payment() : null;
268
269
		if ( $payment instanceof EEI_Payment ) {
270
			$this->log( array( 'Return from Authorization' => $update_info ), $payment );
271
272
			$payment_details = $payment->details();
273
			$transaction = $payment->transaction();
274 View Code Duplication
			if ( ! $transaction instanceof EEI_Transaction ) {
275
				$payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) );
276
				$payment->set_status( $this->_pay_model->failed_status() );
277
				return $payment;
278
			}
279
			$primary_registrant = $transaction->primary_registration();
280
281
			// Check if we still have the token.
282
			if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN']) ) {
283
				$payment->set_status( $this->_pay_model->failed_status() );
284
				return $payment;
285
			}
286
287
			$cdetails_request_dtls = array(
288
				'METHOD' => 'GetExpressCheckoutDetails',
289
				'TOKEN' => $payment_details['TOKEN']
290
			);
291
			// Request Customer Details.
292
			$cdetails_request_response = $this->_ppExpress_request( $cdetails_request_dtls, 'Customer Details', $payment );
293
			$cdetails_rstatus = $this->_ppExpress_check_response( $cdetails_request_response );
294
			$cdata_response_args = ( isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']) ) ? $cdetails_rstatus['args'] : 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
				// Payment Checkout/Capture.
306
				$docheckout_request_response = $this->_ppExpress_request( $docheckout_request_dtls, 'Do Payment', $payment );
307
				$docheckout_rstatus = $this->_ppExpress_check_response( $docheckout_request_response );
308
				$docheckout_response_args = ( isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']) ) ? $docheckout_rstatus['args'] : array();
309
				if ( $docheckout_rstatus['status'] ) {
310
					// All is well, payment approved.
311
					$primary_registration_code = $primary_registrant instanceof EE_Registration ? $primary_registrant->reg_code() : '';
312
					$payment->set_extra_accntng( $primary_registration_code );
313
					$payment->set_amount( isset($docheckout_response_args['PAYMENTINFO_0_AMT']) ? floatval( $docheckout_response_args['PAYMENTINFO_0_AMT'] ) : 0 );
314
					$payment->set_txn_id_chq_nmbr( isset( $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] ) ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] : null );
315
					$payment->set_details( $cdata_response_args );
316
					$payment->set_gateway_response( isset( $docheckout_response_args['PAYMENTINFO_0_ACK'] ) ? $docheckout_response_args['PAYMENTINFO_0_ACK'] : '' );
317
					$payment->set_status( $this->_pay_model->approved_status() );
318 View Code Duplication
				} else {
319
					if ( isset($docheckout_response_args['L_ERRORCODE']) ) {
320
						$payment->set_gateway_response( $docheckout_response_args['L_ERRORCODE'] . '; ' . $docheckout_response_args['L_SHORTMESSAGE'] );
321
					} else {
322
						$payment->set_gateway_response( __( 'Error occurred while trying to Capture the funds.', 'event_espresso' ) );
323
					}
324
					$payment->set_details( $docheckout_response_args );
325
					$payment->set_status( $this->_pay_model->declined_status() );
326
				}
327 View Code Duplication
			} else {
328
				if ( isset($cdata_response_args['L_ERRORCODE']) ) {
329
					$payment->set_gateway_response( $cdata_response_args['L_ERRORCODE'] . '; ' . $cdata_response_args['L_SHORTMESSAGE'] );
330
				} else {
331
					$payment->set_gateway_response( __( 'Error occurred while trying to get payment Details from PayPal.', 'event_espresso' ) );
332
				}
333
				$payment->set_details( $cdata_response_args );
334
				$payment->set_status( $this->_pay_model->failed_status() );
335
			}
336
		} else {
337
			$payment->set_gateway_response( __( 'Error occurred while trying to process the payment.', 'event_espresso' ) );
338
			$payment->set_status( $this->_pay_model->failed_status() );
339
		}
340
341
		return $payment;
342
	}
343
344
345
	/**
346
	 *  Make the Express checkout request.
347
	 *
348
	 *	@param array        $request_params
349
	 *	@param string       $request_text
350
	 *  @param EEI_Payment  $payment
351
	 *	@return mixed
352
	 */
353
	public function _ppExpress_request( $request_params, $request_text, $payment ) {
354
		$request_dtls = array(
355
			'VERSION' => '204.0',
356
			'USER' => urlencode( $this->_api_username ),
357
			'PWD' => urlencode( $this->_api_password ),
358
			'SIGNATURE' => urlencode( $this->_api_signature )
359
		);
360
		$dtls = array_merge( $request_dtls, $request_params );
361
362
		$this->_log_clean_request( $dtls, $payment, $request_text . ' Request' );
363
		// Request Customer Details.
364
		$request_response = wp_remote_post(
365
			$this->_base_gateway_url,
366
			array(
367
				'method' => 'POST',
368
				'timeout' => 45,
369
				'httpversion' => '1.1',
370
				'cookies' => array(),
371
				'headers' => array(),
372
				'body' => http_build_query( $dtls )
373
			)
374
		);
375
		// Log the response.
376
		$this->log( array( $request_text . ' Response' => $request_response), $payment );
377
378
		return $request_response;
379
	}
380
381
382
	/**
383
	 *  Check the response status.
384
	 *
385
	 *	@param mixed        $request_response
386
	 *	@return array
387
	 */
388
	public function _ppExpress_check_response( $request_response ) {
389
		if ( ! is_wp_error( $request_response ) && $request_response['body'] && ! empty($request_response['body'] ) ) {
390
			$response_args = array();
391
			parse_str( urldecode($request_response['body']), $response_args );
392
			if ( isset($response_args['ACK']) 
393
				&& $response_args['ACK'] === 'Success' 
394
				&& ( isset($response_args['PAYERID']) 
395
					|| isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) 
396
					|| ( isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed' ) 
397
					|| isset($response_args['TOKEN']) 
398
				) 
399
			) {
400
				// Response status OK, return response parameters for further processing.
401
				return array('status' => true, 'args' => $response_args);
402
			} else {
403
				if ( isset($response_args['ACK']) ) {
404
					$errors = $this->_get_errors($response_args);
405
					return array( 'status' => false, 'args' => $errors );
406
				} else {
407
					return array( 'status' => false, 'args' => $request_response );
408
				}
409
			}
410
		} else {
411
			// If we got here then there was an error in this request.
412
			return array( 'status' => false, 'args' => $request_response );
413
		}
414
	}
415
416
417
	/**
418
	 *  Log a "Cleared" request.
419
	 *
420
	 *	@param array        $response
0 ignored issues
show
Bug introduced by
There is no parameter named $response. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
421
	 *	@param EEI_Payment  $payment
422
	 *	@param string  		$info
423
	 *	@return void
424
	 */
425
	private function _log_clean_request( $request_prms, $payment, $info ) {
426
		$cleaned_request_data = $request_prms;
427
		unset($cleaned_request_data['PWD']);
428
		unset($cleaned_request_data['USER']);
429
		unset($cleaned_request_data['SIGNATURE']);
430
		$this->log( array($info => $cleaned_request_data), $payment );
431
	}
432
433
434
	/**
435
	 *  Get error from the response data.
436
	 *
437
	 *  @param array	$data_array
438
	 *  @return array
439
	 */
440
	private function _get_errors( $data_array ) {
441
		$errors = array();
442
		$n = 0;
443
		while ( isset($data_array['L_ERRORCODE' . $n . '']) ) {
444
			$l_error_code = isset($data_array['L_ERRORCODE' . $n . '']) ? $data_array['L_ERRORCODE' . $n . ''] : '';
445
			$l_severity_code = isset($data_array['L_SEVERITYCODE' . $n . '']) ? $data_array['L_SEVERITYCODE' . $n . ''] : '';
446
			$l_short_message = isset($data_array['L_SHORTMESSAGE' . $n . '']) ? $data_array['L_SHORTMESSAGE' . $n . ''] : '';
447
			$l_long_message = isset($data_array['L_LONGMESSAGE' . $n . '']) ? $data_array['L_LONGMESSAGE' . $n . ''] : '';
448
449
			if ( $n == 0 ) {
450
				$errors = array(
451
					'L_ERRORCODE' => $l_error_code,
452
					'L_SHORTMESSAGE' => $l_short_message,
453
					'L_LONGMESSAGE' => $l_long_message,
454
					'L_SEVERITYCODE' => $l_severity_code
455
				);
456
			} else {
457
				$errors['L_ERRORCODE'] .= ', ' . $l_error_code;
458
				$errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
459
				$errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
460
				$errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
461
			}
462
463
			$n++;
464
		}
465
466
		return $errors;
467
	}
468
469
}
470
// End of file EEG_Paypal_Express.gateway.php