Passed
Pull Request — master (#98)
by Kiran
04:35
created
includes/gateways/paypal.php 1 patch
Indentation   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -218,261 +218,261 @@  discard block
 block discarded – undo
218 218
 add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 );
219 219
 
220 220
 function wpinv_process_paypal_ipn() {
221
-	// Check the request method is POST
222
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
223
-		return;
224
-	}
225
-
226
-	// Set initial post data to empty string
227
-	$post_data = '';
228
-
229
-	// Fallback just in case post_max_size is lower than needed
230
-	if ( ini_get( 'allow_url_fopen' ) ) {
231
-		$post_data = file_get_contents( 'php://input' );
232
-	} else {
233
-		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
234
-		ini_set( 'post_max_size', '12M' );
235
-	}
236
-	// Start the encoded data collection with notification command
237
-	$encoded_data = 'cmd=_notify-validate';
238
-
239
-	// Get current arg separator
240
-	$arg_separator = wpinv_get_php_arg_separator_output();
241
-
242
-	// Verify there is a post_data
243
-	if ( $post_data || strlen( $post_data ) > 0 ) {
244
-		// Append the data
245
-		$encoded_data .= $arg_separator.$post_data;
246
-	} else {
247
-		// Check if POST is empty
248
-		if ( empty( $_POST ) ) {
249
-			// Nothing to do
250
-			return;
251
-		} else {
252
-			// Loop through each POST
253
-			foreach ( $_POST as $key => $value ) {
254
-				// Encode the value and append the data
255
-				$encoded_data .= $arg_separator."$key=" . urlencode( $value );
256
-			}
257
-		}
258
-	}
259
-
260
-	// Convert collected post data to an array
261
-	parse_str( $encoded_data, $encoded_data_array );
262
-
263
-	foreach ( $encoded_data_array as $key => $value ) {
264
-		if ( false !== strpos( $key, 'amp;' ) ) {
265
-			$new_key = str_replace( '&', '&', $key );
266
-			$new_key = str_replace( 'amp;', '&' , $new_key );
267
-
268
-			unset( $encoded_data_array[ $key ] );
269
-			$encoded_data_array[ $new_key ] = $value;
270
-		}
271
-	}
272
-
273
-	// Get the PayPal redirect uri
274
-	$paypal_redirect = wpinv_get_paypal_redirect( true );
275
-
276
-	if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
277
-		// Validate the IPN
278
-
279
-		$remote_post_vars      = array(
280
-			'method'           => 'POST',
281
-			'timeout'          => 45,
282
-			'redirection'      => 5,
283
-			'httpversion'      => '1.1',
284
-			'blocking'         => true,
285
-			'headers'          => array(
286
-				'host'         => 'www.paypal.com',
287
-				'connection'   => 'close',
288
-				'content-type' => 'application/x-www-form-urlencoded',
289
-				'post'         => '/cgi-bin/webscr HTTP/1.1',
290
-
291
-			),
292
-			'sslverify'        => false,
293
-			'body'             => $encoded_data_array
294
-		);
295
-
296
-		// Get response
297
-		$api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
298
-
299
-		if ( is_wp_error( $api_response ) ) {
300
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
301
-			return; // Something went wrong
302
-		}
303
-
304
-		if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
305
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
306
-			return; // Response not okay
307
-		}
308
-	}
309
-
310
-	// Check if $post_data_array has been populated
311
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
312
-		return;
313
-
314
-	$defaults = array(
315
-		'txn_type'       => '',
316
-		'payment_status' => ''
317
-	);
318
-
319
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
320
-
321
-	$invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
221
+    // Check the request method is POST
222
+    if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
223
+        return;
224
+    }
225
+
226
+    // Set initial post data to empty string
227
+    $post_data = '';
228
+
229
+    // Fallback just in case post_max_size is lower than needed
230
+    if ( ini_get( 'allow_url_fopen' ) ) {
231
+        $post_data = file_get_contents( 'php://input' );
232
+    } else {
233
+        // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
234
+        ini_set( 'post_max_size', '12M' );
235
+    }
236
+    // Start the encoded data collection with notification command
237
+    $encoded_data = 'cmd=_notify-validate';
238
+
239
+    // Get current arg separator
240
+    $arg_separator = wpinv_get_php_arg_separator_output();
241
+
242
+    // Verify there is a post_data
243
+    if ( $post_data || strlen( $post_data ) > 0 ) {
244
+        // Append the data
245
+        $encoded_data .= $arg_separator.$post_data;
246
+    } else {
247
+        // Check if POST is empty
248
+        if ( empty( $_POST ) ) {
249
+            // Nothing to do
250
+            return;
251
+        } else {
252
+            // Loop through each POST
253
+            foreach ( $_POST as $key => $value ) {
254
+                // Encode the value and append the data
255
+                $encoded_data .= $arg_separator."$key=" . urlencode( $value );
256
+            }
257
+        }
258
+    }
259
+
260
+    // Convert collected post data to an array
261
+    parse_str( $encoded_data, $encoded_data_array );
262
+
263
+    foreach ( $encoded_data_array as $key => $value ) {
264
+        if ( false !== strpos( $key, 'amp;' ) ) {
265
+            $new_key = str_replace( '&', '&', $key );
266
+            $new_key = str_replace( 'amp;', '&' , $new_key );
267
+
268
+            unset( $encoded_data_array[ $key ] );
269
+            $encoded_data_array[ $new_key ] = $value;
270
+        }
271
+    }
272
+
273
+    // Get the PayPal redirect uri
274
+    $paypal_redirect = wpinv_get_paypal_redirect( true );
275
+
276
+    if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
277
+        // Validate the IPN
278
+
279
+        $remote_post_vars      = array(
280
+            'method'           => 'POST',
281
+            'timeout'          => 45,
282
+            'redirection'      => 5,
283
+            'httpversion'      => '1.1',
284
+            'blocking'         => true,
285
+            'headers'          => array(
286
+                'host'         => 'www.paypal.com',
287
+                'connection'   => 'close',
288
+                'content-type' => 'application/x-www-form-urlencoded',
289
+                'post'         => '/cgi-bin/webscr HTTP/1.1',
290
+
291
+            ),
292
+            'sslverify'        => false,
293
+            'body'             => $encoded_data_array
294
+        );
295
+
296
+        // Get response
297
+        $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
298
+
299
+        if ( is_wp_error( $api_response ) ) {
300
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
301
+            return; // Something went wrong
302
+        }
303
+
304
+        if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
305
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
306
+            return; // Response not okay
307
+        }
308
+    }
309
+
310
+    // Check if $post_data_array has been populated
311
+    if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
312
+        return;
313
+
314
+    $defaults = array(
315
+        'txn_type'       => '',
316
+        'payment_status' => ''
317
+    );
318
+
319
+    $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
320
+
321
+    $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
322 322
     
323
-	wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
324
-
325
-	if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
326
-		// Allow PayPal IPN types to be processed separately
327
-		do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
328
-	} else {
329
-		// Fallback to web accept just in case the txn_type isn't present
330
-		do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
331
-	}
332
-	exit;
323
+    wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
324
+
325
+    if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
326
+        // Allow PayPal IPN types to be processed separately
327
+        do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
328
+    } else {
329
+        // Fallback to web accept just in case the txn_type isn't present
330
+        do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
331
+    }
332
+    exit;
333 333
 }
334 334
 add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' );
335 335
 
336 336
 function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) {
337
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
338
-		return;
339
-	}
340
-
341
-	if( empty( $invoice_id ) ) {
342
-		return;
343
-	}
344
-
345
-	// Collect payment details
346
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
347
-	$paypal_amount  = $data['mc_gross'];
348
-	$payment_status = strtolower( $data['payment_status'] );
349
-	$currency_code  = strtolower( $data['mc_currency'] );
350
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
351
-	$payment_meta   = wpinv_get_invoice_meta( $invoice_id );
352
-
353
-	if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
354
-		return; // this isn't a PayPal standard IPN
355
-	}
356
-
357
-	// Verify payment recipient
358
-	if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
359
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
360
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
361
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) );
362
-		return;
363
-	}
364
-
365
-	// Verify payment currency
366
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
367
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
368
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
369
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) );
370
-		return;
371
-	}
372
-
373
-	if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
374
-		// This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
375
-		// No email associated with purchase, so store from PayPal
376
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
377
-
378
-		// Setup and store the customer's details
379
-		$user_info = array(
380
-			'user_id'    => '-1',
381
-			'email'      => sanitize_text_field( $data['payer_email'] ),
382
-			'first_name' => sanitize_text_field( $data['first_name'] ),
383
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
384
-			'discount'   => '',
385
-		);
386
-		$user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
387
-		$user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
388
-		$user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
389
-		$user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
390
-		$user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
391
-
392
-		$payment_meta['user_info'] = $user_info;
393
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
394
-	}
395
-
396
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
397
-		// Process a refund
398
-		wpinv_process_paypal_refund( $data, $invoice_id );
399
-	} else {
400
-		if ( get_post_status( $invoice_id ) == 'publish' ) {
401
-			return; // Only paid payments once
402
-		}
403
-
404
-		// Retrieve the total purchase amount (before PayPal)
405
-		$payment_amount = wpinv_payment_total( $invoice_id );
406
-
407
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
408
-			// The prices don't match
409
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
410
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
411
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) );
412
-			return;
413
-		}
414
-		if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
415
-			// Purchase keys don't match
416
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
417
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
418
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) );
419
-			return;
420
-		}
421
-
422
-		if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
423
-			wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) );
424
-			wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
425
-			wpinv_update_payment_status( $invoice_id, 'publish' );
426
-		} else if ( 'wpi-pending' == $payment_status && isset( $data['pending_reason'] ) ) {
427
-			// Look for possible pending reasons, such as an echeck
428
-			$note = '';
429
-
430
-			switch( strtolower( $data['pending_reason'] ) ) {
431
-				case 'echeck' :
432
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
433
-					break;
337
+    if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
338
+        return;
339
+    }
340
+
341
+    if( empty( $invoice_id ) ) {
342
+        return;
343
+    }
344
+
345
+    // Collect payment details
346
+    $purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
347
+    $paypal_amount  = $data['mc_gross'];
348
+    $payment_status = strtolower( $data['payment_status'] );
349
+    $currency_code  = strtolower( $data['mc_currency'] );
350
+    $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
351
+    $payment_meta   = wpinv_get_invoice_meta( $invoice_id );
352
+
353
+    if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
354
+        return; // this isn't a PayPal standard IPN
355
+    }
356
+
357
+    // Verify payment recipient
358
+    if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
359
+        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
360
+        wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
361
+        wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) );
362
+        return;
363
+    }
364
+
365
+    // Verify payment currency
366
+    if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
367
+        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
368
+        wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
369
+        wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) );
370
+        return;
371
+    }
372
+
373
+    if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
374
+        // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
375
+        // No email associated with purchase, so store from PayPal
376
+        wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
377
+
378
+        // Setup and store the customer's details
379
+        $user_info = array(
380
+            'user_id'    => '-1',
381
+            'email'      => sanitize_text_field( $data['payer_email'] ),
382
+            'first_name' => sanitize_text_field( $data['first_name'] ),
383
+            'last_name'  => sanitize_text_field( $data['last_name'] ),
384
+            'discount'   => '',
385
+        );
386
+        $user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
387
+        $user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
388
+        $user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
389
+        $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
390
+        $user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
391
+
392
+        $payment_meta['user_info'] = $user_info;
393
+        wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
394
+    }
395
+
396
+    if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
397
+        // Process a refund
398
+        wpinv_process_paypal_refund( $data, $invoice_id );
399
+    } else {
400
+        if ( get_post_status( $invoice_id ) == 'publish' ) {
401
+            return; // Only paid payments once
402
+        }
403
+
404
+        // Retrieve the total purchase amount (before PayPal)
405
+        $payment_amount = wpinv_payment_total( $invoice_id );
406
+
407
+        if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
408
+            // The prices don't match
409
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
410
+            wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
411
+            wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) );
412
+            return;
413
+        }
414
+        if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
415
+            // Purchase keys don't match
416
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
417
+            wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
418
+            wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) );
419
+            return;
420
+        }
421
+
422
+        if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
423
+            wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) );
424
+            wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
425
+            wpinv_update_payment_status( $invoice_id, 'publish' );
426
+        } else if ( 'wpi-pending' == $payment_status && isset( $data['pending_reason'] ) ) {
427
+            // Look for possible pending reasons, such as an echeck
428
+            $note = '';
429
+
430
+            switch( strtolower( $data['pending_reason'] ) ) {
431
+                case 'echeck' :
432
+                    $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
433
+                    break;
434 434
 				
435 435
                 case 'address' :
436
-					$note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
437
-					break;
436
+                    $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
437
+                    break;
438 438
 				
439 439
                 case 'intl' :
440
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
441
-					break;
440
+                    $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
441
+                    break;
442 442
 				
443 443
                 case 'multi-currency' :
444
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
445
-					break;
444
+                    $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
445
+                    break;
446 446
 				
447 447
                 case 'paymentreview' :
448 448
                 case 'regulatory_review' :
449
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
450
-					break;
449
+                    $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
450
+                    break;
451 451
 				
452 452
                 case 'unilateral' :
453
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
454
-					break;
453
+                    $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
454
+                    break;
455 455
 				
456 456
                 case 'upgrade' :
457
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
458
-					break;
457
+                    $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
458
+                    break;
459 459
 				
460 460
                 case 'verify' :
461
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
462
-					break;
463
-
464
-				case 'other' :
465
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
466
-					break;
467
-			}
468
-
469
-			if ( ! empty( $note ) ) {
470
-				wpinv_insert_payment_note( $invoice_id, $note );
471
-			}
472
-		} else {
473
-			wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) );
474
-		}
475
-	}
461
+                    $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
462
+                    break;
463
+
464
+                case 'other' :
465
+                    $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
466
+                    break;
467
+            }
468
+
469
+            if ( ! empty( $note ) ) {
470
+                wpinv_insert_payment_note( $invoice_id, $note );
471
+            }
472
+        } else {
473
+            wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) );
474
+        }
475
+    }
476 476
 }
477 477
 add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 );
478 478
 
@@ -687,27 +687,27 @@  discard block
 block discarded – undo
687 687
 }
688 688
 
689 689
 function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
690
-	// Collect payment details
690
+    // Collect payment details
691 691
 
692
-	if( empty( $invoice_id ) ) {
693
-		return;
694
-	}
692
+    if( empty( $invoice_id ) ) {
693
+        return;
694
+    }
695 695
 
696
-	if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
697
-		return; // Only refund payments once
698
-	}
696
+    if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
697
+        return; // Only refund payments once
698
+    }
699 699
 
700
-	$payment_amount = wpinv_payment_total( $invoice_id );
701
-	$refund_amount  = $data['mc_gross'] * -1;
700
+    $payment_amount = wpinv_payment_total( $invoice_id );
701
+    $refund_amount  = $data['mc_gross'] * -1;
702 702
 
703
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
704
-		wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) );
705
-		return; // This is a partial refund
706
-	}
703
+    if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
704
+        wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) );
705
+        return; // This is a partial refund
706
+    }
707 707
 
708
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) );
709
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) );
710
-	wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
708
+    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) );
709
+    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) );
710
+    wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
711 711
 }
712 712
 
713 713
 function wpinv_get_paypal_redirect( $ssl_check = false ) {
Please login to merge, or discard this patch.