Passed
Pull Request — master (#377)
by Brian
05:03
created
includes/gateways/bank_transfer.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined( 'ABSPATH' ) ) {
4
+    exit;
5
+}
4 6
 
5 7
 add_action( 'wpinv_bank_transfer_cc_form', '__return_false' );
6 8
 
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_action( 'wpinv_bank_transfer_cc_form', '__return_false' );
5
+add_action('wpinv_bank_transfer_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_bank_transfer_payment( $purchase_data ) {
8
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
9
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
7
+function wpinv_process_bank_transfer_payment($purchase_data) {
8
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
9
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
10 10
     }
11 11
 
12 12
     // Collect payment data
@@ -24,39 +24,39 @@  discard block
 block discarded – undo
24 24
     );
25 25
 
26 26
     // Record the pending payment
27
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
27
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
28 28
     
29
-    if ( !empty( $invoice ) ) {
30
-        wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() );
31
-        wpinv_update_payment_status( $invoice, 'wpi-pending' );
29
+    if (!empty($invoice)) {
30
+        wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key());
31
+        wpinv_update_payment_status($invoice, 'wpi-pending');
32 32
         
33 33
         // Empty the shopping cart
34 34
         wpinv_empty_cart();
35 35
         
36
-        do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data );
36
+        do_action('wpinv_send_to_success_page', $invoice->ID, $payment_data);
37 37
         
38
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
38
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
39 39
     } else {
40
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a bank transfer payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
40
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a bank transfer payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
41 41
         // If errors are present, send the user back to the purchase page so they can be corrected
42
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
42
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
43 43
     }
44 44
 }
45
-add_action( 'wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment' );
45
+add_action('wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment');
46 46
 
47
-function wpinv_show_bank_info( $invoice ) {
48
-    if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending' ) {
49
-        $bank_info = wpinv_get_bank_info( true );
47
+function wpinv_show_bank_info($invoice) {
48
+    if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending') {
49
+        $bank_info = wpinv_get_bank_info(true);
50 50
         ?>
51 51
         <div class="wpinv-bank-details">
52
-            <?php if ( $instructions = wpinv_get_bank_instructions() ) { ?>
53
-            <div class="alert bg-info"><?php echo wpautop( wp_kses_post( $instructions ) ); ?></div>
52
+            <?php if ($instructions = wpinv_get_bank_instructions()) { ?>
53
+            <div class="alert bg-info"><?php echo wpautop(wp_kses_post($instructions)); ?></div>
54 54
             <?php } ?>
55
-            <?php if ( !empty( $bank_info ) ) { ?>
56
-            <h3 class="wpinv-bank-t"><?php echo apply_filters( 'wpinv_receipt_bank_details_title', __( 'Our Bank Details', 'invoicing' ) ); ?></h3>
55
+            <?php if (!empty($bank_info)) { ?>
56
+            <h3 class="wpinv-bank-t"><?php echo apply_filters('wpinv_receipt_bank_details_title', __('Our Bank Details', 'invoicing')); ?></h3>
57 57
             <table class="table table-bordered table-sm wpi-bank-details">
58
-                <?php foreach ( $bank_info as $key => $info ) { ?>
59
-                <tr class="wpi-<?php echo sanitize_html_class( $key );?>"><th class="text-left"><?php echo $info['label'] ;?></th><td><?php echo $info['value'] ;?></td></tr>
58
+                <?php foreach ($bank_info as $key => $info) { ?>
59
+                <tr class="wpi-<?php echo sanitize_html_class($key); ?>"><th class="text-left"><?php echo $info['label']; ?></th><td><?php echo $info['value']; ?></td></tr>
60 60
                 <?php } ?>
61 61
             </table>
62 62
             <?php } ?>
@@ -64,37 +64,37 @@  discard block
 block discarded – undo
64 64
         <?php
65 65
     }
66 66
 }
67
-add_action( 'wpinv_before_receipt_details', 'wpinv_show_bank_info', 10, 1 );
67
+add_action('wpinv_before_receipt_details', 'wpinv_show_bank_info', 10, 1);
68 68
 
69
-function wpinv_invoice_print_bank_info( $invoice ) {
70
-    if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending' ) {
69
+function wpinv_invoice_print_bank_info($invoice) {
70
+    if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending') {
71 71
         ?>
72 72
         <div class="row wpinv-bank-info">
73
-            <?php echo wpinv_show_bank_info( $invoice ); ?>
73
+            <?php echo wpinv_show_bank_info($invoice); ?>
74 74
         </div>
75 75
         <?php
76 76
     }
77 77
 }
78
-add_action( 'wpinv_invoice_print_after_top_content', 'wpinv_invoice_print_bank_info', 10, 1 );
78
+add_action('wpinv_invoice_print_after_top_content', 'wpinv_invoice_print_bank_info', 10, 1);
79 79
 
80
-function wpinv_bank_transfer_send_notification( $invoice_ID, $payment_data = array() ) {
81
-    if ( !empty( $payment_data['gateway'] ) && $payment_data['gateway'] == 'bank_transfer' ) {
80
+function wpinv_bank_transfer_send_notification($invoice_ID, $payment_data = array()) {
81
+    if (!empty($payment_data['gateway']) && $payment_data['gateway'] == 'bank_transfer') {
82 82
         // Send invoice to user.
83
-        wpinv_user_invoice_notification( $invoice_ID );
83
+        wpinv_user_invoice_notification($invoice_ID);
84 84
         
85 85
         // Send invoice to admin.
86
-        wpinv_new_invoice_notification( $invoice_ID );
86
+        wpinv_new_invoice_notification($invoice_ID);
87 87
     }
88 88
 }
89
-add_action( 'wpinv_send_to_success_page', 'wpinv_bank_transfer_send_notification', 10, 2 );
89
+add_action('wpinv_send_to_success_page', 'wpinv_bank_transfer_send_notification', 10, 2);
90 90
 
91
-function wpinv_invoice_email_bank_info( $invoice, $email_type = '', $sent_to_admin = false ) {
92
-    if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending' ) {
91
+function wpinv_invoice_email_bank_info($invoice, $email_type = '', $sent_to_admin = false) {
92
+    if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending') {
93 93
         ?>
94 94
         <div class="wpi-email-row">
95
-            <?php echo wpinv_show_bank_info( $invoice ); ?>
95
+            <?php echo wpinv_show_bank_info($invoice); ?>
96 96
         </div>
97 97
         <?php
98 98
     }
99 99
 }
100
-add_action( 'wpinv_email_invoice_details', 'wpinv_invoice_email_bank_info', 9, 3 );
101 100
\ No newline at end of file
101
+add_action('wpinv_email_invoice_details', 'wpinv_invoice_email_bank_info', 9, 3);
102 102
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/paypal.php 3 patches
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined( 'ABSPATH' ) ) {
4
+    exit;
5
+}
4 6
 
5 7
 add_action( 'wpinv_paypal_cc_form', '__return_false' );
6 8
 add_filter( 'wpinv_paypal_support_subscription', '__return_true' );
@@ -307,8 +309,9 @@  discard block
 block discarded – undo
307 309
 	}
308 310
 
309 311
 	// Check if $post_data_array has been populated
310
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
311
-		return;
312
+	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) {
313
+			return;
314
+	}
312 315
 
313 316
 	$defaults = array(
314 317
 		'txn_type'       => '',
Please login to merge, or discard this patch.
Indentation   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -219,262 +219,262 @@  discard block
 block discarded – undo
219 219
 add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 );
220 220
 
221 221
 function wpinv_process_paypal_ipn() {
222
-	// Check the request method is POST
223
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
224
-		return;
225
-	}
226
-
227
-	// Set initial post data to empty string
228
-	$post_data = '';
229
-
230
-	// Fallback just in case post_max_size is lower than needed
231
-	if ( ini_get( 'allow_url_fopen' ) ) {
232
-		$post_data = file_get_contents( 'php://input' );
233
-	} else {
234
-		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
235
-		ini_set( 'post_max_size', '12M' );
236
-	}
237
-	// Start the encoded data collection with notification command
238
-	$encoded_data = 'cmd=_notify-validate';
239
-
240
-	// Get current arg separator
241
-	$arg_separator = wpinv_get_php_arg_separator_output();
242
-
243
-	// Verify there is a post_data
244
-	if ( $post_data || strlen( $post_data ) > 0 ) {
245
-		// Append the data
246
-		$encoded_data .= $arg_separator.$post_data;
247
-	} else {
248
-		// Check if POST is empty
249
-		if ( empty( $_POST ) ) {
250
-			// Nothing to do
251
-			return;
252
-		} else {
253
-			// Loop through each POST
254
-			foreach ( $_POST as $key => $value ) {
255
-				// Encode the value and append the data
256
-				$encoded_data .= $arg_separator."$key=" . urlencode( $value );
257
-			}
258
-		}
259
-	}
260
-
261
-	// Convert collected post data to an array
262
-	wp_parse_str( $encoded_data, $encoded_data_array );
263
-
264
-	foreach ( $encoded_data_array as $key => $value ) {
265
-		if ( false !== strpos( $key, 'amp;' ) ) {
266
-			$new_key = str_replace( '&amp;', '&', $key );
267
-			$new_key = str_replace( 'amp;', '&' , $new_key );
268
-
269
-			unset( $encoded_data_array[ $key ] );
270
-			$encoded_data_array[ $new_key ] = $value;
271
-		}
272
-	}
273
-
274
-	// Get the PayPal redirect uri
275
-	$paypal_redirect = wpinv_get_paypal_redirect( true );
276
-
277
-	if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
278
-		// Validate the IPN
279
-
280
-		$remote_post_vars      = array(
281
-			'method'           => 'POST',
282
-			'timeout'          => 45,
283
-			'redirection'      => 5,
284
-			'httpversion'      => '1.1',
285
-			'blocking'         => true,
286
-			'headers'          => array(
287
-				'host'         => 'www.paypal.com',
288
-				'connection'   => 'close',
289
-				'content-type' => 'application/x-www-form-urlencoded',
290
-				'post'         => '/cgi-bin/webscr HTTP/1.1',
291
-
292
-			),
293
-			'sslverify'        => false,
294
-			'body'             => $encoded_data_array
295
-		);
296
-
297
-		// Get response
298
-		$api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
299
-
300
-		if ( is_wp_error( $api_response ) ) {
301
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
302
-			return; // Something went wrong
303
-		}
304
-
305
-		if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
306
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
307
-			return; // Response not okay
308
-		}
309
-	}
310
-
311
-	// Check if $post_data_array has been populated
312
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
313
-		return;
314
-
315
-	$defaults = array(
316
-		'txn_type'       => '',
317
-		'payment_status' => ''
318
-	);
319
-
320
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
321
-
322
-	$invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
222
+    // Check the request method is POST
223
+    if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
224
+        return;
225
+    }
226
+
227
+    // Set initial post data to empty string
228
+    $post_data = '';
229
+
230
+    // Fallback just in case post_max_size is lower than needed
231
+    if ( ini_get( 'allow_url_fopen' ) ) {
232
+        $post_data = file_get_contents( 'php://input' );
233
+    } else {
234
+        // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
235
+        ini_set( 'post_max_size', '12M' );
236
+    }
237
+    // Start the encoded data collection with notification command
238
+    $encoded_data = 'cmd=_notify-validate';
239
+
240
+    // Get current arg separator
241
+    $arg_separator = wpinv_get_php_arg_separator_output();
242
+
243
+    // Verify there is a post_data
244
+    if ( $post_data || strlen( $post_data ) > 0 ) {
245
+        // Append the data
246
+        $encoded_data .= $arg_separator.$post_data;
247
+    } else {
248
+        // Check if POST is empty
249
+        if ( empty( $_POST ) ) {
250
+            // Nothing to do
251
+            return;
252
+        } else {
253
+            // Loop through each POST
254
+            foreach ( $_POST as $key => $value ) {
255
+                // Encode the value and append the data
256
+                $encoded_data .= $arg_separator."$key=" . urlencode( $value );
257
+            }
258
+        }
259
+    }
260
+
261
+    // Convert collected post data to an array
262
+    wp_parse_str( $encoded_data, $encoded_data_array );
263
+
264
+    foreach ( $encoded_data_array as $key => $value ) {
265
+        if ( false !== strpos( $key, 'amp;' ) ) {
266
+            $new_key = str_replace( '&amp;', '&', $key );
267
+            $new_key = str_replace( 'amp;', '&' , $new_key );
268
+
269
+            unset( $encoded_data_array[ $key ] );
270
+            $encoded_data_array[ $new_key ] = $value;
271
+        }
272
+    }
273
+
274
+    // Get the PayPal redirect uri
275
+    $paypal_redirect = wpinv_get_paypal_redirect( true );
276
+
277
+    if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
278
+        // Validate the IPN
279
+
280
+        $remote_post_vars      = array(
281
+            'method'           => 'POST',
282
+            'timeout'          => 45,
283
+            'redirection'      => 5,
284
+            'httpversion'      => '1.1',
285
+            'blocking'         => true,
286
+            'headers'          => array(
287
+                'host'         => 'www.paypal.com',
288
+                'connection'   => 'close',
289
+                'content-type' => 'application/x-www-form-urlencoded',
290
+                'post'         => '/cgi-bin/webscr HTTP/1.1',
291
+
292
+            ),
293
+            'sslverify'        => false,
294
+            'body'             => $encoded_data_array
295
+        );
296
+
297
+        // Get response
298
+        $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
299
+
300
+        if ( is_wp_error( $api_response ) ) {
301
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
302
+            return; // Something went wrong
303
+        }
304
+
305
+        if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
306
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
307
+            return; // Response not okay
308
+        }
309
+    }
310
+
311
+    // Check if $post_data_array has been populated
312
+    if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
313
+        return;
314
+
315
+    $defaults = array(
316
+        'txn_type'       => '',
317
+        'payment_status' => ''
318
+    );
319
+
320
+    $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
321
+
322
+    $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
323 323
     
324
-	wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
325
-	wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ );
326
-
327
-	if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
328
-		// Allow PayPal IPN types to be processed separately
329
-		do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
330
-	} else {
331
-		// Fallback to web accept just in case the txn_type isn't present
332
-		do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
333
-	}
334
-	exit;
324
+    wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
325
+    wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ );
326
+
327
+    if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
328
+        // Allow PayPal IPN types to be processed separately
329
+        do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
330
+    } else {
331
+        // Fallback to web accept just in case the txn_type isn't present
332
+        do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
333
+    }
334
+    exit;
335 335
 }
336 336
 add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' );
337 337
 
338 338
 function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) {
339
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
340
-		return;
341
-	}
342
-
343
-	if( empty( $invoice_id ) ) {
344
-		return;
345
-	}
346
-
347
-	// Collect payment details
348
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
349
-	$paypal_amount  = $data['mc_gross'];
350
-	$payment_status = strtolower( $data['payment_status'] );
351
-	$currency_code  = strtolower( $data['mc_currency'] );
352
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
353
-	$payment_meta   = wpinv_get_invoice_meta( $invoice_id );
354
-
355
-	if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
356
-		return; // this isn't a PayPal standard IPN
357
-	}
358
-
359
-	// Verify payment recipient
360
-	if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
361
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
362
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
363
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true );
364
-		return;
365
-	}
366
-
367
-	// Verify payment currency
368
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
369
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
370
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
371
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true );
372
-		return;
373
-	}
374
-
375
-	if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
376
-		// This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
377
-		// No email associated with purchase, so store from PayPal
378
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
379
-
380
-		// Setup and store the customer's details
381
-		$user_info = array(
382
-			'user_id'    => '-1',
383
-			'email'      => sanitize_text_field( $data['payer_email'] ),
384
-			'first_name' => sanitize_text_field( $data['first_name'] ),
385
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
386
-			'discount'   => '',
387
-		);
388
-		$user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
389
-		$user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
390
-		$user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
391
-		$user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
392
-		$user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
393
-
394
-		$payment_meta['user_info'] = $user_info;
395
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
396
-	}
397
-
398
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
399
-		// Process a refund
400
-		wpinv_process_paypal_refund( $data, $invoice_id );
401
-	} else {
402
-		if ( get_post_status( $invoice_id ) == 'publish' ) {
403
-			return; // Only paid payments once
404
-		}
405
-
406
-		// Retrieve the total purchase amount (before PayPal)
407
-		$payment_amount = wpinv_payment_total( $invoice_id );
408
-
409
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
410
-			// The prices don't match
411
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
412
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
413
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true );
414
-			return;
415
-		}
416
-		if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
417
-			// Purchase keys don't match
418
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
419
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
420
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true );
421
-			return;
422
-		}
423
-
424
-		if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
425
-			wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true );
426
-			wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
427
-			wpinv_update_payment_status( $invoice_id, 'publish' );
428
-		} else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
429
-			// Look for possible pending reasons, such as an echeck
430
-			$note = '';
431
-
432
-			switch( strtolower( $data['pending_reason'] ) ) {
433
-				case 'echeck' :
434
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
435
-					break;
339
+    if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
340
+        return;
341
+    }
342
+
343
+    if( empty( $invoice_id ) ) {
344
+        return;
345
+    }
346
+
347
+    // Collect payment details
348
+    $purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
349
+    $paypal_amount  = $data['mc_gross'];
350
+    $payment_status = strtolower( $data['payment_status'] );
351
+    $currency_code  = strtolower( $data['mc_currency'] );
352
+    $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
353
+    $payment_meta   = wpinv_get_invoice_meta( $invoice_id );
354
+
355
+    if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
356
+        return; // this isn't a PayPal standard IPN
357
+    }
358
+
359
+    // Verify payment recipient
360
+    if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
361
+        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
362
+        wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
363
+        wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true );
364
+        return;
365
+    }
366
+
367
+    // Verify payment currency
368
+    if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
369
+        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
370
+        wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
371
+        wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true );
372
+        return;
373
+    }
374
+
375
+    if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
376
+        // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
377
+        // No email associated with purchase, so store from PayPal
378
+        wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
379
+
380
+        // Setup and store the customer's details
381
+        $user_info = array(
382
+            'user_id'    => '-1',
383
+            'email'      => sanitize_text_field( $data['payer_email'] ),
384
+            'first_name' => sanitize_text_field( $data['first_name'] ),
385
+            'last_name'  => sanitize_text_field( $data['last_name'] ),
386
+            'discount'   => '',
387
+        );
388
+        $user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
389
+        $user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
390
+        $user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
391
+        $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
392
+        $user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
393
+
394
+        $payment_meta['user_info'] = $user_info;
395
+        wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
396
+    }
397
+
398
+    if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
399
+        // Process a refund
400
+        wpinv_process_paypal_refund( $data, $invoice_id );
401
+    } else {
402
+        if ( get_post_status( $invoice_id ) == 'publish' ) {
403
+            return; // Only paid payments once
404
+        }
405
+
406
+        // Retrieve the total purchase amount (before PayPal)
407
+        $payment_amount = wpinv_payment_total( $invoice_id );
408
+
409
+        if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
410
+            // The prices don't match
411
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
412
+            wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
413
+            wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true );
414
+            return;
415
+        }
416
+        if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
417
+            // Purchase keys don't match
418
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
419
+            wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
420
+            wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true );
421
+            return;
422
+        }
423
+
424
+        if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
425
+            wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true );
426
+            wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
427
+            wpinv_update_payment_status( $invoice_id, 'publish' );
428
+        } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
429
+            // Look for possible pending reasons, such as an echeck
430
+            $note = '';
431
+
432
+            switch( strtolower( $data['pending_reason'] ) ) {
433
+                case 'echeck' :
434
+                    $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
435
+                    break;
436 436
 				
437 437
                 case 'address' :
438
-					$note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
439
-					break;
438
+                    $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
439
+                    break;
440 440
 				
441 441
                 case 'intl' :
442
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
443
-					break;
442
+                    $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
443
+                    break;
444 444
 				
445 445
                 case 'multi-currency' :
446
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
447
-					break;
446
+                    $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
447
+                    break;
448 448
 				
449 449
                 case 'paymentreview' :
450 450
                 case 'regulatory_review' :
451
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
452
-					break;
451
+                    $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
452
+                    break;
453 453
 				
454 454
                 case 'unilateral' :
455
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
456
-					break;
455
+                    $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
456
+                    break;
457 457
 				
458 458
                 case 'upgrade' :
459
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
460
-					break;
459
+                    $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
460
+                    break;
461 461
 				
462 462
                 case 'verify' :
463
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
464
-					break;
465
-
466
-				case 'other' :
467
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
468
-					break;
469
-			}
470
-
471
-			if ( ! empty( $note ) ) {
472
-				wpinv_insert_payment_note( $invoice_id, $note, '', '', true );
473
-			}
474
-		} else {
475
-			wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true );
476
-		}
477
-	}
463
+                    $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
464
+                    break;
465
+
466
+                case 'other' :
467
+                    $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
468
+                    break;
469
+            }
470
+
471
+            if ( ! empty( $note ) ) {
472
+                wpinv_insert_payment_note( $invoice_id, $note, '', '', true );
473
+            }
474
+        } else {
475
+            wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true );
476
+        }
477
+    }
478 478
 }
479 479
 add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 );
480 480
 
@@ -668,34 +668,34 @@  discard block
 block discarded – undo
668 668
 }
669 669
 
670 670
 function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
671
-	// Collect payment details
671
+    // Collect payment details
672 672
 
673
-	if( empty( $invoice_id ) ) {
674
-		return;
675
-	}
673
+    if( empty( $invoice_id ) ) {
674
+        return;
675
+    }
676 676
 
677
-	if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
678
-		return; // Only refund payments once
679
-	}
677
+    if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
678
+        return; // Only refund payments once
679
+    }
680 680
 
681
-	$payment_amount = wpinv_payment_total( $invoice_id );
682
-	$refund_amount  = $data['mc_gross'] * -1;
681
+    $payment_amount = wpinv_payment_total( $invoice_id );
682
+    $refund_amount  = $data['mc_gross'] * -1;
683 683
 
684
-	do_action( 'wpinv_paypal_refund_request', $data, $invoice_id );
684
+    do_action( 'wpinv_paypal_refund_request', $data, $invoice_id );
685 685
 
686
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
687
-		wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
686
+    if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
687
+        wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
688 688
 
689
-		do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount );
689
+        do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount );
690 690
 
691
-		return; // This is a partial refund
692
-	}
691
+        return; // This is a partial refund
692
+    }
693 693
 
694
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
695
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true );
696
-	wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
694
+    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
695
+    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true );
696
+    wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
697 697
 
698
-	do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id );
698
+    do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id );
699 699
 }
700 700
 
701 701
 function wpinv_get_paypal_redirect( $ssl_check = false ) {
Please login to merge, or discard this patch.
Spacing   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_action( 'wpinv_paypal_cc_form', '__return_false' );
6
-add_filter( 'wpinv_paypal_support_subscription', '__return_true' );
5
+add_action('wpinv_paypal_cc_form', '__return_false');
6
+add_filter('wpinv_paypal_support_subscription', '__return_true');
7 7
 
8 8
 
9
-function wpinv_paypal_gateway_description_sandbox_notice( $description, $gateway ) {
10
-    if ( 'paypal' == $gateway && wpinv_is_test_mode( 'paypal' ) ) {
9
+function wpinv_paypal_gateway_description_sandbox_notice($description, $gateway) {
10
+    if ('paypal' == $gateway && wpinv_is_test_mode('paypal')) {
11 11
         $description .= '<br>' . sprintf(
12
-            __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
12
+            __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'),
13 13
             '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
14 14
             '</a>'
15 15
         );
@@ -17,11 +17,11 @@  discard block
 block discarded – undo
17 17
     return $description;
18 18
 
19 19
 }
20
-add_filter( 'wpinv_gateway_description', 'wpinv_paypal_gateway_description_sandbox_notice', 10, 2 );
20
+add_filter('wpinv_gateway_description', 'wpinv_paypal_gateway_description_sandbox_notice', 10, 2);
21 21
 
22
-function wpinv_process_paypal_payment( $purchase_data ) {
23
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
24
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
22
+function wpinv_process_paypal_payment($purchase_data) {
23
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
24
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
25 25
     }
26 26
 
27 27
     // Collect payment data
@@ -39,24 +39,24 @@  discard block
 block discarded – undo
39 39
     );
40 40
 
41 41
     // Record the pending payment
42
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
42
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
43 43
 
44 44
     // Check payment
45
-    if ( ! $invoice ) {
45
+    if (!$invoice) {
46 46
         // Record the error
47
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
47
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
48 48
         // Problems? send back
49
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
49
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
50 50
     } else {
51 51
         // Only send to PayPal if the pending payment is created successfully
52
-        $listener_url = wpinv_get_ipn_url( 'paypal' );
52
+        $listener_url = wpinv_get_ipn_url('paypal');
53 53
 
54 54
         // Get the success url
55
-        $return_url = add_query_arg( array(
55
+        $return_url = add_query_arg(array(
56 56
                 'payment-confirm' => 'paypal',
57 57
                 'invoice-id'      => $invoice->ID,
58 58
                 'utm_nooverride'  => 1
59
-            ), get_permalink( wpinv_get_option( 'success_page', false ) ) );
59
+            ), get_permalink(wpinv_get_option('success_page', false)));
60 60
 
61 61
         // Get the PayPal redirect uri
62 62
         $paypal_redirect = wpinv_get_paypal_redirect();
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
         $paypal_args = array(
66 66
             'cmd'           => '_cart',
67 67
             'upload'        => '1',
68
-            'business'      => wpinv_get_option( 'paypal_email', false ),
68
+            'business'      => wpinv_get_option('paypal_email', false),
69 69
             'email'         => $invoice->get_email(),
70 70
             'first_name'    => $invoice->get_first_name(),
71 71
             'last_name'     => $invoice->get_last_name(),
@@ -74,88 +74,88 @@  discard block
 block discarded – undo
74 74
             'shipping'      => '0',
75 75
             'no_note'       => '1',
76 76
             'currency_code' => $invoice->get_currency(),
77
-            'charset'       => get_bloginfo( 'charset' ),
77
+            'charset'       => get_bloginfo('charset'),
78 78
             'custom'        => $invoice->ID,
79 79
             'rm'            => is_ssl() ? 2 : 1,
80
-            'return'        => esc_url_raw( $return_url ),
80
+            'return'        => esc_url_raw($return_url),
81 81
             'cancel_return' => $invoice->get_checkout_payment_url(),
82 82
             'notify_url'    => $listener_url,
83
-            'cbt'           => get_bloginfo( 'name' ),
83
+            'cbt'           => get_bloginfo('name'),
84 84
             'bn'            => 'WPInvoicing_SP',
85 85
         );
86 86
 
87 87
         // Add cart items
88 88
         $i = 1;
89
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
90
-            foreach ( $purchase_data['cart_details'] as $item ) {
89
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
90
+            foreach ($purchase_data['cart_details'] as $item) {
91 91
                 $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1;
92
-                $item_amount = wpinv_sanitize_amount( $item['subtotal'] / $item['quantity'], 2 );
92
+                $item_amount = wpinv_sanitize_amount($item['subtotal'] / $item['quantity'], 2);
93 93
 
94
-                if ( $item_amount <= 0 ) {
94
+                if ($item_amount <= 0) {
95 95
                     $item_amount = 0;
96 96
                 }
97 97
 
98
-                $paypal_args['item_number_' . $i ]      = $item['id'];
99
-                $paypal_args['item_name_' . $i ]        = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) );
100
-                $paypal_args['quantity_' . $i ]         = $item['quantity'];
101
-                $paypal_args['amount_' . $i ]           = $item_amount;
102
-                $paypal_args['discount_amount_' . $i ]  = wpinv_sanitize_amount( $item['discount'], 2 );
98
+                $paypal_args['item_number_' . $i]      = $item['id'];
99
+                $paypal_args['item_name_' . $i]        = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8'));
100
+                $paypal_args['quantity_' . $i]         = $item['quantity'];
101
+                $paypal_args['amount_' . $i]           = $item_amount;
102
+                $paypal_args['discount_amount_' . $i]  = wpinv_sanitize_amount($item['discount'], 2);
103 103
 
104 104
                 $i++;
105 105
             }
106 106
         }
107 107
 
108 108
         // Add taxes to the cart
109
-        if ( wpinv_use_taxes() && $invoice->is_taxable() ) {
110
-            $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_tax(), 2 );
109
+        if (wpinv_use_taxes() && $invoice->is_taxable()) {
110
+            $paypal_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_tax(), 2);
111 111
         }
112 112
 
113
-        $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice );
113
+        $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice);
114 114
 
115 115
         // Build query
116
-        $paypal_redirect .= http_build_query( $paypal_args );
116
+        $paypal_redirect .= http_build_query($paypal_args);
117 117
 
118 118
         // Fix for some sites that encode the entities
119
-        $paypal_redirect = str_replace( '&amp;', '&', $paypal_redirect );
119
+        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
120 120
 
121 121
         // Get rid of cart contents
122 122
         wpinv_empty_cart();
123 123
         
124 124
         // Redirect to PayPal
125
-        wp_redirect( $paypal_redirect );
125
+        wp_redirect($paypal_redirect);
126 126
         exit;
127 127
     }
128 128
 }
129
-add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' );
129
+add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment');
130 130
 
131
-function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) {
132
-    if ( $invoice->is_recurring() && $subscription = wpinv_get_subscription( $invoice->ID ) ) {
131
+function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) {
132
+    if ($invoice->is_recurring() && $subscription = wpinv_get_subscription($invoice->ID)) {
133 133
 
134
-        $period             = strtoupper( substr( $subscription->period, 0, 1) );
134
+        $period             = strtoupper(substr($subscription->period, 0, 1));
135 135
         $interval           = $subscription->frequency;
136 136
         $bill_times         = (int) $subscription->bill_times;
137 137
         
138
-        $initial_amount     = wpinv_sanitize_amount( $invoice->get_total(), 2 );
139
-        $recurring_amount   = wpinv_sanitize_amount( $invoice->get_recurring_details( 'total' ), 2 );
138
+        $initial_amount     = wpinv_sanitize_amount($invoice->get_total(), 2);
139
+        $recurring_amount   = wpinv_sanitize_amount($invoice->get_recurring_details('total'), 2);
140 140
         
141 141
         $paypal_args['cmd'] = '_xclick-subscriptions';
142 142
         $paypal_args['sra'] = '1';
143 143
         $paypal_args['src'] = '1';
144 144
         
145 145
         // Set item description
146
-        $item_name                  = wpinv_get_cart_item_name( array( 'id' => $subscription->product_id ) );
147
-        $paypal_args['item_name']   = stripslashes_deep( html_entity_decode( $item_name, ENT_COMPAT, 'UTF-8' ) );
146
+        $item_name                  = wpinv_get_cart_item_name(array('id' => $subscription->product_id));
147
+        $paypal_args['item_name']   = stripslashes_deep(html_entity_decode($item_name, ENT_COMPAT, 'UTF-8'));
148 148
         $paypal_args['item_number'] = $subscription->product_id;
149
-        $item   = new WPInv_Item( $subscription->period );
149
+        $item = new WPInv_Item($subscription->period);
150 150
 
151
-        if ( $invoice->is_free_trial() && $item->has_free_trial() ) {
151
+        if ($invoice->is_free_trial() && $item->has_free_trial()) {
152 152
             $paypal_args['a1']  = $initial_amount;
153 153
             $paypal_args['p1']  = $item->get_trial_interval();
154 154
             $paypal_args['t1']  = $item->get_trial_period();
155 155
             
156 156
             // Set the recurring amount
157 157
             $paypal_args['a3']  = $recurring_amount;
158
-        } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) {
158
+        } else if ($initial_amount != $recurring_amount && $bill_times != 1) {
159 159
             $paypal_args['a1']  = $initial_amount;
160 160
             $paypal_args['p1']  = $interval;
161 161
             $paypal_args['t1']  = $period;
@@ -163,63 +163,63 @@  discard block
 block discarded – undo
163 163
             // Set the recurring amount
164 164
             $paypal_args['a3']  = $recurring_amount;
165 165
             
166
-            if ( $bill_times > 1 ) {
166
+            if ($bill_times > 1) {
167 167
                 $bill_times--;
168 168
             }
169 169
         } else {
170
-            $paypal_args['a3']  = $initial_amount;
170
+            $paypal_args['a3'] = $initial_amount;
171 171
         }
172 172
         
173 173
         $paypal_args['p3']  = $interval;
174 174
         $paypal_args['t3']  = $period;
175 175
         
176
-        if ( $bill_times > 1 ) {
176
+        if ($bill_times > 1) {
177 177
             // Make sure it's not over the max of 52
178
-            $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
178
+            $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
179 179
         }
180 180
                 
181 181
         // Remove cart items
182 182
         $i = 1;
183
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
184
-            foreach ( $purchase_data['cart_details'] as $item ) {                
185
-                if ( isset( $paypal_args['item_number_' . $i] ) ) {
186
-                    unset( $paypal_args['item_number_' . $i] );
183
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
184
+            foreach ($purchase_data['cart_details'] as $item) {                
185
+                if (isset($paypal_args['item_number_' . $i])) {
186
+                    unset($paypal_args['item_number_' . $i]);
187 187
                 }
188
-                if ( isset( $paypal_args['item_name_' . $i] ) ) {
189
-                    unset( $paypal_args['item_name_' . $i] );
188
+                if (isset($paypal_args['item_name_' . $i])) {
189
+                    unset($paypal_args['item_name_' . $i]);
190 190
                 }
191
-                if ( isset( $paypal_args['quantity_' . $i] ) ) {
192
-                    unset( $paypal_args['quantity_' . $i] );
191
+                if (isset($paypal_args['quantity_' . $i])) {
192
+                    unset($paypal_args['quantity_' . $i]);
193 193
                 }
194
-                if ( isset( $paypal_args['amount_' . $i] ) ) {
195
-                    unset( $paypal_args['amount_' . $i] );
194
+                if (isset($paypal_args['amount_' . $i])) {
195
+                    unset($paypal_args['amount_' . $i]);
196 196
                 }
197
-                if ( isset( $paypal_args['discount_amount_' . $i] ) ) {
198
-                    unset( $paypal_args['discount_amount_' . $i] );
197
+                if (isset($paypal_args['discount_amount_' . $i])) {
198
+                    unset($paypal_args['discount_amount_' . $i]);
199 199
                 }
200 200
 
201 201
                 $i++;
202 202
             }
203 203
         }
204 204
         
205
-        if ( isset( $paypal_args['tax_cart'] ) ) {
206
-            unset( $paypal_args['tax_cart'] );
205
+        if (isset($paypal_args['tax_cart'])) {
206
+            unset($paypal_args['tax_cart']);
207 207
         }
208 208
                 
209
-        if ( isset( $paypal_args['upload'] ) ) {
210
-            unset( $paypal_args['upload'] );
209
+        if (isset($paypal_args['upload'])) {
210
+            unset($paypal_args['upload']);
211 211
         }
212 212
         
213
-        $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice );
213
+        $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice);
214 214
     }
215 215
     
216 216
     return $paypal_args;
217 217
 }
218
-add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 );
218
+add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3);
219 219
 
220 220
 function wpinv_process_paypal_ipn() {
221 221
 	// Check the request method is POST
222
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
222
+	if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
223 223
 		return;
224 224
 	}
225 225
 
@@ -227,11 +227,11 @@  discard block
 block discarded – undo
227 227
 	$post_data = '';
228 228
 
229 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' );
230
+	if (ini_get('allow_url_fopen')) {
231
+		$post_data = file_get_contents('php://input');
232 232
 	} else {
233 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' );
234
+		ini_set('post_max_size', '12M');
235 235
 	}
236 236
 	// Start the encoded data collection with notification command
237 237
 	$encoded_data = 'cmd=_notify-validate';
@@ -240,43 +240,43 @@  discard block
 block discarded – undo
240 240
 	$arg_separator = wpinv_get_php_arg_separator_output();
241 241
 
242 242
 	// Verify there is a post_data
243
-	if ( $post_data || strlen( $post_data ) > 0 ) {
243
+	if ($post_data || strlen($post_data) > 0) {
244 244
 		// Append the data
245
-		$encoded_data .= $arg_separator.$post_data;
245
+		$encoded_data .= $arg_separator . $post_data;
246 246
 	} else {
247 247
 		// Check if POST is empty
248
-		if ( empty( $_POST ) ) {
248
+		if (empty($_POST)) {
249 249
 			// Nothing to do
250 250
 			return;
251 251
 		} else {
252 252
 			// Loop through each POST
253
-			foreach ( $_POST as $key => $value ) {
253
+			foreach ($_POST as $key => $value) {
254 254
 				// Encode the value and append the data
255
-				$encoded_data .= $arg_separator."$key=" . urlencode( $value );
255
+				$encoded_data .= $arg_separator . "$key=" . urlencode($value);
256 256
 			}
257 257
 		}
258 258
 	}
259 259
 
260 260
 	// Convert collected post data to an array
261
-	wp_parse_str( $encoded_data, $encoded_data_array );
261
+	wp_parse_str($encoded_data, $encoded_data_array);
262 262
 
263
-	foreach ( $encoded_data_array as $key => $value ) {
264
-		if ( false !== strpos( $key, 'amp;' ) ) {
265
-			$new_key = str_replace( '&amp;', '&', $key );
266
-			$new_key = str_replace( 'amp;', '&' , $new_key );
263
+	foreach ($encoded_data_array as $key => $value) {
264
+		if (false !== strpos($key, 'amp;')) {
265
+			$new_key = str_replace('&amp;', '&', $key);
266
+			$new_key = str_replace('amp;', '&', $new_key);
267 267
 
268
-			unset( $encoded_data_array[ $key ] );
269
-			$encoded_data_array[ $new_key ] = $value;
268
+			unset($encoded_data_array[$key]);
269
+			$encoded_data_array[$new_key] = $value;
270 270
 		}
271 271
 	}
272 272
 
273 273
 	// Get the PayPal redirect uri
274
-	$paypal_redirect = wpinv_get_paypal_redirect( true );
274
+	$paypal_redirect = wpinv_get_paypal_redirect(true);
275 275
 
276
-	if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
276
+	if (!wpinv_get_option('disable_paypal_verification', false)) {
277 277
 		// Validate the IPN
278 278
 
279
-		$remote_post_vars      = array(
279
+		$remote_post_vars = array(
280 280
 			'method'           => 'POST',
281 281
 			'timeout'          => 45,
282 282
 			'redirection'      => 5,
@@ -294,21 +294,21 @@  discard block
 block discarded – undo
294 294
 		);
295 295
 
296 296
 		// Get response
297
-		$api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
297
+		$api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars);
298 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 ) ) );
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 301
 			return; // Something went wrong
302 302
 		}
303 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 ) ) );
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 306
 			return; // Response not okay
307 307
 		}
308 308
 	}
309 309
 
310 310
 	// Check if $post_data_array has been populated
311
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
311
+	if (!is_array($encoded_data_array) && !empty($encoded_data_array))
312 312
 		return;
313 313
 
314 314
 	$defaults = array(
@@ -316,265 +316,265 @@  discard block
 block discarded – undo
316 316
 		'payment_status' => ''
317 317
 	);
318 318
 
319
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
319
+	$encoded_data_array = wp_parse_args($encoded_data_array, $defaults);
320 320
 
321
-	$invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
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
-	wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ );
323
+	wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__);
324
+	wpinv_error_log($encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__);
325 325
 
326
-	if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
326
+	if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) {
327 327
 		// Allow PayPal IPN types to be processed separately
328
-		do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
328
+		do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id);
329 329
 	} else {
330 330
 		// Fallback to web accept just in case the txn_type isn't present
331
-		do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
331
+		do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id);
332 332
 	}
333 333
 	exit;
334 334
 }
335
-add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' );
335
+add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn');
336 336
 
337
-function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) {
338
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
337
+function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) {
338
+	if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') {
339 339
 		return;
340 340
 	}
341 341
 
342
-	if( empty( $invoice_id ) ) {
342
+	if (empty($invoice_id)) {
343 343
 		return;
344 344
 	}
345 345
 
346 346
 	// Collect payment details
347
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
347
+	$purchase_key   = isset($data['invoice']) ? $data['invoice'] : $data['item_number'];
348 348
 	$paypal_amount  = $data['mc_gross'];
349
-	$payment_status = strtolower( $data['payment_status'] );
350
-	$currency_code  = strtolower( $data['mc_currency'] );
351
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
352
-	$payment_meta   = wpinv_get_invoice_meta( $invoice_id );
349
+	$payment_status = strtolower($data['payment_status']);
350
+	$currency_code  = strtolower($data['mc_currency']);
351
+	$business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']);
352
+	$payment_meta   = wpinv_get_invoice_meta($invoice_id);
353 353
 
354
-	if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
354
+	if (wpinv_get_payment_gateway($invoice_id) != 'paypal') {
355 355
 		return; // this isn't a PayPal standard IPN
356 356
 	}
357 357
 
358 358
 	// Verify payment recipient
359
-	if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
360
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
361
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
362
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true );
359
+	if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) {
360
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
361
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
362
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing'), '', '', true);
363 363
 		return;
364 364
 	}
365 365
 
366 366
 	// Verify payment currency
367
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
368
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
369
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
370
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true );
367
+	if ($currency_code != strtolower($payment_meta['currency'])) {
368
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
369
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
370
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing'), '', '', true);
371 371
 		return;
372 372
 	}
373 373
 
374
-	if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
374
+	if (!wpinv_get_payment_user_email($invoice_id)) {
375 375
 		// This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
376 376
 		// No email associated with purchase, so store from PayPal
377
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
377
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']);
378 378
 
379 379
 		// Setup and store the customer's details
380 380
 		$user_info = array(
381 381
 			'user_id'    => '-1',
382
-			'email'      => sanitize_text_field( $data['payer_email'] ),
383
-			'first_name' => sanitize_text_field( $data['first_name'] ),
384
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
382
+			'email'      => sanitize_text_field($data['payer_email']),
383
+			'first_name' => sanitize_text_field($data['first_name']),
384
+			'last_name'  => sanitize_text_field($data['last_name']),
385 385
 			'discount'   => '',
386 386
 		);
387
-		$user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
388
-		$user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
389
-		$user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
390
-		$user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
391
-		$user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
387
+		$user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false;
388
+		$user_info['city']    = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false;
389
+		$user_info['state']   = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false;
390
+		$user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false;
391
+		$user_info['zip']     = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false;
392 392
 
393 393
 		$payment_meta['user_info'] = $user_info;
394
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
394
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta);
395 395
 	}
396 396
 
397
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
397
+	if ($payment_status == 'refunded' || $payment_status == 'reversed') {
398 398
 		// Process a refund
399
-		wpinv_process_paypal_refund( $data, $invoice_id );
399
+		wpinv_process_paypal_refund($data, $invoice_id);
400 400
 	} else {
401
-		if ( get_post_status( $invoice_id ) == 'publish' ) {
401
+		if (get_post_status($invoice_id) == 'publish') {
402 402
 			return; // Only paid payments once
403 403
 		}
404 404
 
405 405
 		// Retrieve the total purchase amount (before PayPal)
406
-		$payment_amount = wpinv_payment_total( $invoice_id );
406
+		$payment_amount = wpinv_payment_total($invoice_id);
407 407
 
408
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
408
+		if (number_format((float) $paypal_amount, 2) < number_format((float) $payment_amount, 2)) {
409 409
 			// The prices don't match
410
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
411
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
412
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true );
410
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
411
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
412
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing'), '', '', true);
413 413
 			return;
414 414
 		}
415
-		if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
415
+		if ($purchase_key != wpinv_get_payment_key($invoice_id)) {
416 416
 			// Purchase keys don't match
417
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
418
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
419
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true );
417
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
418
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
419
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing'), '', '', true);
420 420
 			return;
421 421
 		}
422 422
 
423
-		if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
424
-			wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true );
425
-			wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
426
-			wpinv_update_payment_status( $invoice_id, 'publish' );
427
-		} else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
423
+		if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) {
424
+			wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true);
425
+			wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']);
426
+			wpinv_update_payment_status($invoice_id, 'publish');
427
+		} else if ('pending' == $payment_status && isset($data['pending_reason'])) {
428 428
 			// Look for possible pending reasons, such as an echeck
429 429
 			$note = '';
430 430
 
431
-			switch( strtolower( $data['pending_reason'] ) ) {
431
+			switch (strtolower($data['pending_reason'])) {
432 432
 				case 'echeck' :
433
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
433
+					$note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing');
434 434
 					break;
435 435
 				
436 436
                 case 'address' :
437
-					$note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
437
+					$note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing');
438 438
 					break;
439 439
 				
440 440
                 case 'intl' :
441
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
441
+					$note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing');
442 442
 					break;
443 443
 				
444 444
                 case 'multi-currency' :
445
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
445
+					$note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing');
446 446
 					break;
447 447
 				
448 448
                 case 'paymentreview' :
449 449
                 case 'regulatory_review' :
450
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
450
+					$note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing');
451 451
 					break;
452 452
 				
453 453
                 case 'unilateral' :
454
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
454
+					$note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing');
455 455
 					break;
456 456
 				
457 457
                 case 'upgrade' :
458
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
458
+					$note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing');
459 459
 					break;
460 460
 				
461 461
                 case 'verify' :
462
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
462
+					$note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing');
463 463
 					break;
464 464
 
465 465
 				case 'other' :
466
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
466
+					$note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing');
467 467
 					break;
468 468
 			}
469 469
 
470
-			if ( ! empty( $note ) ) {
471
-				wpinv_insert_payment_note( $invoice_id, $note, '', '', true );
470
+			if (!empty($note)) {
471
+				wpinv_insert_payment_note($invoice_id, $note, '', '', true);
472 472
 			}
473 473
 		} else {
474
-			wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true );
474
+			wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status), '', '', true);
475 475
 		}
476 476
 	}
477 477
 }
478
-add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 );
478
+add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2);
479 479
 
480 480
 // Process PayPal subscription sign ups
481
-add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' );
481
+add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup');
482 482
 
483 483
 // Process PayPal subscription payments
484
-add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' );
484
+add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment');
485 485
 
486 486
 // Process PayPal subscription cancellations
487
-add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' );
487
+add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel');
488 488
 
489 489
 // Process PayPal subscription end of term notices
490
-add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' );
490
+add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot');
491 491
 
492 492
 // Process PayPal payment failed
493
-add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' );
493
+add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed');
494 494
 
495 495
 
496 496
 /**
497 497
  * Process the subscription started IPN.
498 498
  */
499
-function wpinv_process_paypal_subscr_signup( $ipn_data ) {
500
-    $parent_invoice_id = absint( $ipn_data['custom'] );
501
-    if( empty( $parent_invoice_id ) ) {
499
+function wpinv_process_paypal_subscr_signup($ipn_data) {
500
+    $parent_invoice_id = absint($ipn_data['custom']);
501
+    if (empty($parent_invoice_id)) {
502 502
         return;
503 503
     }
504 504
 
505
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
506
-    if ( empty( $invoice ) ) {
505
+    $invoice = wpinv_get_invoice($parent_invoice_id);
506
+    if (empty($invoice)) {
507 507
         return;
508 508
     }
509 509
 
510
-    if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) {
511
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ), '', '', true);
512
-        if ( !empty( $ipn_data['txn_id'] ) ) {
513
-            wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] );
510
+    if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) {
511
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice']), '', '', true);
512
+        if (!empty($ipn_data['txn_id'])) {
513
+            wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']);
514 514
         }
515 515
     }
516 516
 
517
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
518
-    if ( false === $subscription ) {
517
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
518
+    if (false === $subscription) {
519 519
         return;
520 520
     }
521 521
     
522
-    wpinv_update_payment_status( $parent_invoice_id, 'publish' );
522
+    wpinv_update_payment_status($parent_invoice_id, 'publish');
523 523
     sleep(1);
524
-    wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true );
525
-    update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $ipn_data['subscr_id']);
524
+    wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true);
525
+    update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $ipn_data['subscr_id']);
526 526
 
527 527
     $status     = 'trialling' == $subscription->status ? 'trialling' : 'active';
528
-    $diff_days  = absint( ( ( strtotime( $subscription->expiration ) - strtotime( $subscription->created ) ) / DAY_IN_SECONDS ) );
529
-    $created    = date_i18n( 'Y-m-d H:i:s' );
530
-    $expiration = date_i18n( 'Y-m-d 23:59:59', ( strtotime( $created ) + ( $diff_days * DAY_IN_SECONDS ) ) );
528
+    $diff_days  = absint(((strtotime($subscription->expiration) - strtotime($subscription->created)) / DAY_IN_SECONDS));
529
+    $created    = date_i18n('Y-m-d H:i:s');
530
+    $expiration = date_i18n('Y-m-d 23:59:59', (strtotime($created) + ($diff_days * DAY_IN_SECONDS)));
531 531
 
532 532
     // Retrieve pending subscription from database and update it's status to active and set proper profile ID
533
-    $subscription->update( array( 'profile_id' => $ipn_data['subscr_id'], 'status' => $status, 'created' => $created, 'expiration' => $expiration ) );
533
+    $subscription->update(array('profile_id' => $ipn_data['subscr_id'], 'status' => $status, 'created' => $created, 'expiration' => $expiration));
534 534
 }
535 535
 
536 536
 /**
537 537
  * Process the subscription payment received IPN.
538 538
  */
539
-function wpinv_process_paypal_subscr_payment( $ipn_data ) {
540
-    $parent_invoice_id = absint( $ipn_data['custom'] );
539
+function wpinv_process_paypal_subscr_payment($ipn_data) {
540
+    $parent_invoice_id = absint($ipn_data['custom']);
541 541
 
542
-    $parent_invoice = wpinv_get_invoice( $parent_invoice_id );
543
-    if ( empty( $parent_invoice ) ) {
542
+    $parent_invoice = wpinv_get_invoice($parent_invoice_id);
543
+    if (empty($parent_invoice)) {
544 544
         return;
545 545
     }
546 546
 
547
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
548
-    if ( false === $subscription ) {
547
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
548
+    if (false === $subscription) {
549 549
         return;
550 550
     }
551 551
 
552
-    $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id );
552
+    $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id);
553 553
     $times_billed   = $subscription->get_times_billed();
554
-    $signup_date    = strtotime( $subscription->created );
555
-    $today          = date( 'Ynd', $signup_date ) == date( 'Ynd', strtotime( $ipn_data['payment_date'] ) );
554
+    $signup_date    = strtotime($subscription->created);
555
+    $today          = date('Ynd', $signup_date) == date('Ynd', strtotime($ipn_data['payment_date']));
556 556
 
557 557
     // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet.
558
-    if ( (empty($times_billed) || $today) && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) {
559
-        wpinv_update_payment_status( $parent_invoice_id, 'publish' );
558
+    if ((empty($times_billed) || $today) && (!$transaction_id || $transaction_id == $parent_invoice_id)) {
559
+        wpinv_update_payment_status($parent_invoice_id, 'publish');
560 560
         sleep(1);
561 561
         
562 562
         // This is the very first payment
563
-        wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] );
564
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true );
563
+        wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']);
564
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true);
565 565
         return;
566 566
     }
567 567
 
568
-    if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) {
568
+    if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) {
569 569
         return; // Payment already recorded
570 570
     }
571 571
 
572
-    $currency_code = strtolower( $ipn_data['mc_currency'] );
572
+    $currency_code = strtolower($ipn_data['mc_currency']);
573 573
 
574 574
     // verify details
575
-    if ( $currency_code != strtolower( wpinv_get_currency() ) ) {
575
+    if ($currency_code != strtolower(wpinv_get_currency())) {
576 576
         // the currency code is invalid
577
-        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) );
577
+        wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data)));
578 578
         return;
579 579
     }
580 580
 
@@ -584,11 +584,11 @@  discard block
 block discarded – undo
584 584
         'gateway'        => 'paypal'
585 585
     );
586 586
     
587
-    $invoice_id = $subscription->add_payment( $args );
587
+    $invoice_id = $subscription->add_payment($args);
588 588
 
589
-    if ( $invoice_id > 0 ) {
590
-        wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true );
591
-        wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true );
589
+    if ($invoice_id > 0) {
590
+        wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true);
591
+        wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true);
592 592
 
593 593
         $subscription->renew();
594 594
     }
@@ -597,10 +597,10 @@  discard block
 block discarded – undo
597 597
 /**
598 598
  * Process the subscription canceled IPN.
599 599
  */
600
-function wpinv_process_paypal_subscr_cancel( $ipn_data ) {
601
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
600
+function wpinv_process_paypal_subscr_cancel($ipn_data) {
601
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
602 602
 
603
-    if( false === $subscription ) {
603
+    if (false === $subscription) {
604 604
         return;
605 605
     }
606 606
 
@@ -610,10 +610,10 @@  discard block
 block discarded – undo
610 610
 /**
611 611
  * Process the subscription expired IPN.
612 612
  */
613
-function wpinv_process_paypal_subscr_eot( $ipn_data ) {
614
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
613
+function wpinv_process_paypal_subscr_eot($ipn_data) {
614
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
615 615
 
616
-    if( false === $subscription ) {
616
+    if (false === $subscription) {
617 617
         return;
618 618
     }
619 619
 
@@ -623,40 +623,40 @@  discard block
 block discarded – undo
623 623
 /**
624 624
  * Process the subscription payment failed IPN.
625 625
  */
626
-function wpinv_process_paypal_subscr_failed( $ipn_data ) {
627
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
626
+function wpinv_process_paypal_subscr_failed($ipn_data) {
627
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
628 628
 
629
-    if( false === $subscription ) {
629
+    if (false === $subscription) {
630 630
         return;
631 631
     }
632 632
 
633 633
     $subscription->failing();
634 634
 
635
-    do_action( 'wpinv_recurring_payment_failed', $subscription );
635
+    do_action('wpinv_recurring_payment_failed', $subscription);
636 636
 }
637 637
 
638 638
 /**
639 639
  * Retrieve the subscription this IPN notice is for.
640 640
  */
641
-function wpinv_get_paypal_subscription( $ipn_data = array() ) {
642
-    $parent_invoice_id = absint( $ipn_data['custom'] );
641
+function wpinv_get_paypal_subscription($ipn_data = array()) {
642
+    $parent_invoice_id = absint($ipn_data['custom']);
643 643
 
644
-    if( empty( $parent_invoice_id ) ) {
644
+    if (empty($parent_invoice_id)) {
645 645
         return false;
646 646
     }
647 647
 
648
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
649
-    if ( empty( $invoice ) ) {
648
+    $invoice = wpinv_get_invoice($parent_invoice_id);
649
+    if (empty($invoice)) {
650 650
         return false;
651 651
     }
652 652
 
653
-    $subscription = new WPInv_Subscription( $ipn_data['subscr_id'], true );
653
+    $subscription = new WPInv_Subscription($ipn_data['subscr_id'], true);
654 654
 
655
-    if ( ! ( ! empty( $subscription ) && $subscription->id > 0 ) ) {
656
-        $subscription = wpinv_get_subscription( $parent_invoice_id );
655
+    if (!(!empty($subscription) && $subscription->id > 0)) {
656
+        $subscription = wpinv_get_subscription($parent_invoice_id);
657 657
 
658
-        if ( ! empty( $subscription ) && $subscription->id > 0 ) {
659
-            $subscription->update( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) );
658
+        if (!empty($subscription) && $subscription->id > 0) {
659
+            $subscription->update(array('profile_id' => sanitize_text_field($ipn_data['subscr_id'])));
660 660
         } else {
661 661
             return false;
662 662
         }
@@ -666,152 +666,152 @@  discard block
 block discarded – undo
666 666
 
667 667
 }
668 668
 
669
-function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
669
+function wpinv_process_paypal_refund($data, $invoice_id = 0) {
670 670
 	// Collect payment details
671 671
 
672
-	if( empty( $invoice_id ) ) {
672
+	if (empty($invoice_id)) {
673 673
 		return;
674 674
 	}
675 675
 
676
-	if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
676
+	if (get_post_status($invoice_id) == 'wpi-refunded') {
677 677
 		return; // Only refund payments once
678 678
 	}
679 679
 
680
-	$payment_amount = wpinv_payment_total( $invoice_id );
680
+	$payment_amount = wpinv_payment_total($invoice_id);
681 681
 	$refund_amount  = $data['mc_gross'] * -1;
682 682
 
683
-	do_action( 'wpinv_paypal_refund_request', $data, $invoice_id );
683
+	do_action('wpinv_paypal_refund_request', $data, $invoice_id);
684 684
 
685
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
686
-		wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
685
+	if (number_format((float) $refund_amount, 2) < number_format((float) $payment_amount, 2)) {
686
+		wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing'), (float) $refund_amount . ' ' . $data['mc_currency'], $data['parent_txn_id'], $data['reason_code']), '', '', true);
687 687
 
688
-		do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount );
688
+		do_action('wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount);
689 689
 
690 690
 		return; // This is a partial refund
691 691
 	}
692 692
 
693
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
694
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true );
695
-	wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
693
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code']), '', '', true);
694
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true);
695
+	wpinv_update_payment_status($invoice_id, 'wpi-refunded');
696 696
 
697
-	do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id );
697
+	do_action('wpinv_paypal_invoice_fully_refunded', $data, $invoice_id);
698 698
 }
699 699
 
700
-function wpinv_get_paypal_redirect( $ssl_check = false ) {
701
-    return apply_filters( 'wpinv_paypal_uri', wpinv_is_test_mode( 'paypal' ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?' );
700
+function wpinv_get_paypal_redirect($ssl_check = false) {
701
+    return apply_filters('wpinv_paypal_uri', wpinv_is_test_mode('paypal') ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?');
702 702
 }
703 703
 
704
-function wpinv_paypal_success_page_content( $content ) {
704
+function wpinv_paypal_success_page_content($content) {
705 705
     global $wpi_invoice;
706 706
     
707 707
     $session = wpinv_get_checkout_session();
708 708
 
709
-    if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] )  ) {
709
+    if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) {
710 710
         return $content;
711 711
     }
712 712
 
713
-    $invoice_id = ! empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] );
713
+    $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']);
714 714
 
715
-    if ( empty(  $invoice_id ) ) {
715
+    if (empty($invoice_id)) {
716 716
         return $content;
717 717
     }
718 718
 
719
-    $wpi_invoice = wpinv_get_invoice( $invoice_id );
719
+    $wpi_invoice = wpinv_get_invoice($invoice_id);
720 720
     
721
-    if ( ! empty( $wpi_invoice ) && 'wpi-pending' == $wpi_invoice->status ) {
721
+    if (!empty($wpi_invoice) && 'wpi-pending' == $wpi_invoice->status) {
722 722
         // Payment is still pending so show processing indicator to fix the Race Condition, issue #
723 723
         ob_start();
724
-        wpinv_get_template_part( 'wpinv-payment-processing' );
724
+        wpinv_get_template_part('wpinv-payment-processing');
725 725
         $content = ob_get_clean();
726 726
     }
727 727
 
728 728
     return $content;
729 729
 }
730
-add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' );
730
+add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content');
731 731
 
732
-function wpinv_paypal_get_transaction_id( $invoice_id ) {
732
+function wpinv_paypal_get_transaction_id($invoice_id) {
733 733
     $transaction_id = '';
734
-    $notes = wpinv_get_invoice_notes( $invoice_id );
734
+    $notes = wpinv_get_invoice_notes($invoice_id);
735 735
 
736
-    foreach ( $notes as $note ) {
737
-        if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) {
736
+    foreach ($notes as $note) {
737
+        if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) {
738 738
             $transaction_id = $match[1];
739 739
             continue;
740 740
         }
741 741
     }
742 742
 
743
-    return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id );
743
+    return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id);
744 744
 }
745
-add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 );
745
+add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1);
746 746
 
747
-function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
748
-    if ( $transaction_id == $invoice_id ) {
747
+function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) {
748
+    if ($transaction_id == $invoice_id) {
749 749
         $transaction_link = $transaction_id;
750 750
     } else {
751
-        if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) {
751
+        if (!empty($invoice) && !empty($invoice->mode)) {
752 752
             $mode = $invoice->mode;
753 753
         } else {
754
-            $mode = wpinv_is_test_mode( 'paypal' ) ? 'test' : 'live';
754
+            $mode = wpinv_is_test_mode('paypal') ? 'test' : 'live';
755 755
         }
756 756
 
757 757
         $sandbox = $mode == 'test' ? '.sandbox' : '';
758 758
         $transaction_url = 'https://www' . $sandbox . '.paypal.com/webscr?cmd=_history-details-from-hub&id=' . $transaction_id;
759 759
 
760
-        $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>';
760
+        $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>';
761 761
     }
762 762
 
763
-    return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $transaction_id, $invoice );
763
+    return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $transaction_id, $invoice);
764 764
 }
765
-add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 );
765
+add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3);
766 766
 
767
-function wpinv_paypal_profile_id_link( $profile_id, $subscription ) {
767
+function wpinv_paypal_profile_id_link($profile_id, $subscription) {
768 768
     $link = $profile_id;
769 769
 
770
-    if ( ! empty( $profile_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) {
771
-        $invoice = wpinv_get_invoice( $invoice_id );
770
+    if (!empty($profile_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) {
771
+        $invoice = wpinv_get_invoice($invoice_id);
772 772
 
773
-        if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) {
773
+        if (!empty($invoice) && !empty($invoice->mode)) {
774 774
             $mode = $invoice->mode;
775 775
         } else {
776
-            $mode = wpinv_is_test_mode( 'paypal' ) ? 'test' : 'live';
776
+            $mode = wpinv_is_test_mode('paypal') ? 'test' : 'live';
777 777
         }
778 778
 
779 779
         $sandbox = $mode == 'test' ? '.sandbox' : '';
780 780
         $url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=' . $profile_id;
781 781
 
782
-        $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $profile_id . '</a>';
782
+        $link = '<a href="' . esc_url($url) . '" target="_blank">' . $profile_id . '</a>';
783 783
     }
784 784
     
785
-    return apply_filters( 'wpinv_paypal_profile_id_link', $link, $profile_id, $subscription );
785
+    return apply_filters('wpinv_paypal_profile_id_link', $link, $profile_id, $subscription);
786 786
 }
787
-add_filter( 'wpinv_subscription_profile_link_paypal', 'wpinv_paypal_profile_id_link', 10, 2 );
787
+add_filter('wpinv_subscription_profile_link_paypal', 'wpinv_paypal_profile_id_link', 10, 2);
788 788
 
789
-function wpinv_paypal_transaction_id_link( $transaction_id, $subscription ) {
790
-    if ( ! empty( $transaction_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) {
791
-        $invoice = wpinv_get_invoice( $invoice_id );
789
+function wpinv_paypal_transaction_id_link($transaction_id, $subscription) {
790
+    if (!empty($transaction_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) {
791
+        $invoice = wpinv_get_invoice($invoice_id);
792 792
 
793
-        if ( ! empty( $invoice ) ) {
794
-            return wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice );
793
+        if (!empty($invoice)) {
794
+            return wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice);
795 795
         }        
796 796
     }
797 797
     
798 798
     return $transaction_id;
799 799
 }
800
-add_filter( 'wpinv_subscription_transaction_link_paypal', 'wpinv_paypal_transaction_id_link', 10, 2 );
800
+add_filter('wpinv_subscription_transaction_link_paypal', 'wpinv_paypal_transaction_id_link', 10, 2);
801 801
 
802 802
 function wpinv_is_paypal_valid_for_use() {
803
-    return in_array( wpinv_get_currency(), apply_filters( 'wpinv_paypal_supported_currencies', array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ) ) );
803
+    return in_array(wpinv_get_currency(), apply_filters('wpinv_paypal_supported_currencies', array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR')));
804 804
 }
805 805
 
806
-function wpinv_check_paypal_currency_support( $gateway_list ) {
807
-    if ( isset( $gateway_list['paypal'] ) && ! wpinv_is_paypal_valid_for_use() ) {
808
-        unset( $gateway_list['paypal'] );
806
+function wpinv_check_paypal_currency_support($gateway_list) {
807
+    if (isset($gateway_list['paypal']) && !wpinv_is_paypal_valid_for_use()) {
808
+        unset($gateway_list['paypal']);
809 809
     }
810 810
     return $gateway_list;
811 811
 }
812
-add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1 );
812
+add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1);
813 813
 
814
-function wpinv_gateway_paypal_button_label( $label ) {
815
-    return __( 'Proceed to PayPal', 'invoicing' );
814
+function wpinv_gateway_paypal_button_label($label) {
815
+    return __('Proceed to PayPal', 'invoicing');
816 816
 }
817
-add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 );
818 817
\ No newline at end of file
818
+add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1);
819 819
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-address-functions.php 3 patches
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -95,20 +95,24 @@
 block discarded – undo
95 95
     }
96 96
 
97 97
     if ( !empty( $user_info ) ) {
98
-        if( empty( $address['first_name'] ) )
99
-            $address['first_name'] = $user_info->first_name;
98
+        if( empty( $address['first_name'] ) ) {
99
+                    $address['first_name'] = $user_info->first_name;
100
+        }
100 101
         
101
-        if( empty( $address['last_name'] ) )
102
-            $address['last_name'] = $user_info->last_name;
102
+        if( empty( $address['last_name'] ) ) {
103
+                    $address['last_name'] = $user_info->last_name;
104
+        }
103 105
     }
104 106
     
105 107
     $address['name'] = trim( trim( $address['first_name'] . ' ' . $address['last_name'] ), "," );
106 108
     
107
-    if( empty( $address['state'] ) && $with_default )
108
-        $address['state'] = wpinv_get_default_state();
109
+    if( empty( $address['state'] ) && $with_default ) {
110
+            $address['state'] = wpinv_get_default_state();
111
+    }
109 112
 
110
-    if( empty( $address['country'] ) && $with_default )
111
-        $address['country'] = wpinv_get_default_country();
113
+    if( empty( $address['country'] ) && $with_default ) {
114
+            $address['country'] = wpinv_get_default_country();
115
+    }
112 116
 
113 117
 
114 118
     return $address;
Please login to merge, or discard this patch.
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -13,9 +13,9 @@  discard block
 block discarded – undo
13 13
 
14 14
 
15 15
 function wpinv_get_default_country() {
16
-	$country = wpinv_get_option( 'default_country', 'UK' );
16
+    $country = wpinv_get_option( 'default_country', 'UK' );
17 17
 
18
-	return apply_filters( 'wpinv_default_country', $country );
18
+    return apply_filters( 'wpinv_default_country', $country );
19 19
 }
20 20
 
21 21
 /**
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
  */
27 27
 function wpinv_sanitize_country( $country ) {
28 28
 
29
-	// Enure the country is specified
29
+    // Enure the country is specified
30 30
     if ( empty( $country ) ) {
31 31
         $country = wpinv_get_default_country();
32 32
     }
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 }
57 57
 
58 58
 function wpinv_get_default_state() {
59
-	$state = wpinv_get_option( 'default_state', false );
59
+    $state = wpinv_get_option( 'default_state', false );
60 60
 
61
-	return apply_filters( 'wpinv_default_state', $state );
61
+    return apply_filters( 'wpinv_default_state', $state );
62 62
 }
63 63
 
64 64
 function wpinv_state_name( $state_code = '', $country_code = '' ) {
@@ -166,11 +166,11 @@  discard block
 block discarded – undo
166 166
 
167 167
     $country = wpinv_sanitize_country( $country );
168 168
     
169
-	foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
170
-		if ( false !== array_search( $country, $countries, true ) ) {
171
-			return $continent_code;
172
-		}
173
-	}
169
+    foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
170
+        if ( false !== array_search( $country, $countries, true ) ) {
171
+            return $continent_code;
172
+        }
173
+    }
174 174
 
175 175
     return '';
176 176
     
@@ -462,30 +462,30 @@  discard block
 block discarded – undo
462 462
 }
463 463
 
464 464
 function wpinv_get_states_field() {
465
-	if( empty( $_POST['country'] ) ) {
466
-		$_POST['country'] = wpinv_get_default_country();
467
-	}
468
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
465
+    if( empty( $_POST['country'] ) ) {
466
+        $_POST['country'] = wpinv_get_default_country();
467
+    }
468
+    $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
469 469
 
470
-	if( !empty( $states ) ) {
471
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
470
+    if( !empty( $states ) ) {
471
+        $sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
472 472
         
473 473
         $args = array(
474
-			'name'    => $sanitized_field_name,
475
-			'id'      => $sanitized_field_name,
476
-			'class'   => $sanitized_field_name . 'custom-select wpinv-select wpi_select2',
477
-			'options' => array_merge( array( '' => '' ), $states ),
478
-			'show_option_all'  => false,
479
-			'show_option_none' => false
480
-		);
481
-
482
-		$response = wpinv_html_select( $args );
483
-
484
-	} else {
485
-		$response = 'nostates';
486
-	}
474
+            'name'    => $sanitized_field_name,
475
+            'id'      => $sanitized_field_name,
476
+            'class'   => $sanitized_field_name . 'custom-select wpinv-select wpi_select2',
477
+            'options' => array_merge( array( '' => '' ), $states ),
478
+            'show_option_all'  => false,
479
+            'show_option_none' => false
480
+        );
481
+
482
+        $response = wpinv_html_select( $args );
483
+
484
+    } else {
485
+        $response = 'nostates';
486
+    }
487 487
 
488
-	return $response;
488
+    return $response;
489 489
 }
490 490
 
491 491
 function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
@@ -503,46 +503,46 @@  discard block
 block discarded – undo
503 503
  */
504 504
 function wpinv_get_address_formats() {
505 505
 
506
-		return apply_filters( 'wpinv_localisation_address_formats',
507
-			array(
508
-				'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
509
-				'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
510
-				'AT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
511
-				'BE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
512
-				'CA'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}}&nbsp;&nbsp;{{zip}}\n{{country}}",
513
-				'CH'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
514
-				'CL'      => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}",
515
-				'CN'      => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}",
516
-				'CZ'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
517
-				'DE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
518
-				'EE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
519
-				'FI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
520
-				'DK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
521
-				'FR'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}",
522
-				'HK'      => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}",
523
-				'HU'      => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}",
524
-				'IN'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}",
525
-				'IS'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
526
-				'IT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}",
527
-				'JP'      => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}",
528
-				'TW'      => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}",
529
-				'LI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
530
-				'NL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
531
-				'NZ'      => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}",
532
-				'NO'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
533
-				'PL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
534
-				'PT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
535
-				'SK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
536
-				'RS'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
537
-				'SI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
538
-				'ES'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}",
539
-				'SE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
540
-				'TR'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}",
541
-				'UG'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}",
542
-				'US'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}",
543
-				'VN'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}",
544
-			)
545
-		);
506
+        return apply_filters( 'wpinv_localisation_address_formats',
507
+            array(
508
+                'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
509
+                'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
510
+                'AT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
511
+                'BE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
512
+                'CA'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}}&nbsp;&nbsp;{{zip}}\n{{country}}",
513
+                'CH'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
514
+                'CL'      => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}",
515
+                'CN'      => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}",
516
+                'CZ'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
517
+                'DE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
518
+                'EE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
519
+                'FI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
520
+                'DK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
521
+                'FR'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}",
522
+                'HK'      => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}",
523
+                'HU'      => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}",
524
+                'IN'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}",
525
+                'IS'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
526
+                'IT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}",
527
+                'JP'      => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}",
528
+                'TW'      => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}",
529
+                'LI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
530
+                'NL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
531
+                'NZ'      => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}",
532
+                'NO'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
533
+                'PL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
534
+                'PT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
535
+                'SK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
536
+                'RS'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
537
+                'SI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
538
+                'ES'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}",
539
+                'SE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
540
+                'TR'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}",
541
+                'UG'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}",
542
+                'US'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}",
543
+                'VN'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}",
544
+            )
545
+        );
546 546
 }
547 547
 
548 548
 /**
@@ -559,21 +559,21 @@  discard block
 block discarded – undo
559 559
     }
560 560
 
561 561
     // Get all formats.
562
-	$formats = wpinv_get_address_formats();
562
+    $formats = wpinv_get_address_formats();
563 563
 
564
-	// Get format for the specified country.
565
-	$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
564
+    // Get format for the specified country.
565
+    $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
566 566
     
567 567
     /**
568
-	 * Filters the address format to use on Invoices.
568
+     * Filters the address format to use on Invoices.
569 569
      * 
570 570
      * New lines will be replaced by a `br` element. Double new lines will be replaced by a paragraph. HTML tags are allowed.
571
-	 *
572
-	 * @since 1.0.13
573
-	 *
574
-	 * @param string $format  The address format to use.
571
+     *
572
+     * @since 1.0.13
573
+     *
574
+     * @param string $format  The address format to use.
575 575
      * @param string $country The country who's address format is being retrieved.
576
-	 */
576
+     */
577 577
     return apply_filters( 'wpinv_get_full_address_format', $format, $country );
578 578
 }
579 579
 
@@ -594,8 +594,8 @@  discard block
 block discarded – undo
594 594
         'country'           => '',
595 595
         'zip'               => '',
596 596
         'first_name'        => '',
597
-		'last_name'         => '',
598
-		'company'           => '',
597
+        'last_name'         => '',
598
+        'company'           => '',
599 599
     );
600 600
 
601 601
     $args    = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' );
@@ -616,14 +616,14 @@  discard block
 block discarded – undo
616 616
     $args['country_code']= $country;
617 617
 
618 618
     /**
619
-	 * Filters the address format replacements to use on Invoices.
619
+     * Filters the address format replacements to use on Invoices.
620 620
      * 
621
-	 *
622
-	 * @since 1.0.13
623
-	 *
624
-	 * @param array $replacements  The address replacements to use.
621
+     *
622
+     * @since 1.0.13
623
+     *
624
+     * @param array $replacements  The address replacements to use.
625 625
      * @param array $billing_details  The billing details to use.
626
-	 */
626
+     */
627 627
     $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details );
628 628
 
629 629
     $return = array();
@@ -646,5 +646,5 @@  discard block
 block discarded – undo
646 646
  * @return string
647 647
  */
648 648
 function wpinv_trim_formatted_address_line( $line ) {
649
-	return trim( $line, ', ' );
649
+    return trim( $line, ', ' );
650 650
 }
651 651
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 
15 15
 function wpinv_get_default_country() {
16
-	$country = wpinv_get_option( 'default_country', 'UK' );
16
+	$country = wpinv_get_option('default_country', 'UK');
17 17
 
18
-	return apply_filters( 'wpinv_default_country', $country );
18
+	return apply_filters('wpinv_default_country', $country);
19 19
 }
20 20
 
21 21
 /**
@@ -24,66 +24,66 @@  discard block
 block discarded – undo
24 24
  * @param string $country The country code to sanitize
25 25
  * @return array
26 26
  */
27
-function wpinv_sanitize_country( $country ) {
27
+function wpinv_sanitize_country($country) {
28 28
 
29 29
 	// Enure the country is specified
30
-    if ( empty( $country ) ) {
30
+    if (empty($country)) {
31 31
         $country = wpinv_get_default_country();
32 32
     }
33
-    return trim( wpinv_utf8_strtoupper( $country ) );
33
+    return trim(wpinv_utf8_strtoupper($country));
34 34
 
35 35
 }
36 36
 
37
-function wpinv_is_base_country( $country ) {
37
+function wpinv_is_base_country($country) {
38 38
     $base_country = wpinv_get_default_country();
39 39
     
40
-    if ( $base_country === 'UK' ) {
40
+    if ($base_country === 'UK') {
41 41
         $base_country = 'GB';
42 42
     }
43
-    if ( $country == 'UK' ) {
43
+    if ($country == 'UK') {
44 44
         $country = 'GB';
45 45
     }
46 46
 
47
-    return ( $country && $country === $base_country ) ? true : false;
47
+    return ($country && $country === $base_country) ? true : false;
48 48
 }
49 49
 
50
-function wpinv_country_name( $country_code = '' ) { 
50
+function wpinv_country_name($country_code = '') { 
51 51
     $countries = wpinv_get_country_list();
52 52
     $country_code = $country_code == 'UK' ? 'GB' : $country_code;
53
-    $country = isset( $countries[$country_code] ) ? $countries[$country_code] : $country_code;
53
+    $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code;
54 54
 
55
-    return apply_filters( 'wpinv_country_name', $country, $country_code );
55
+    return apply_filters('wpinv_country_name', $country, $country_code);
56 56
 }
57 57
 
58 58
 function wpinv_get_default_state() {
59
-	$state = wpinv_get_option( 'default_state', false );
59
+	$state = wpinv_get_option('default_state', false);
60 60
 
61
-	return apply_filters( 'wpinv_default_state', $state );
61
+	return apply_filters('wpinv_default_state', $state);
62 62
 }
63 63
 
64
-function wpinv_state_name( $state_code = '', $country_code = '' ) {
64
+function wpinv_state_name($state_code = '', $country_code = '') {
65 65
     $state = $state_code;
66 66
     
67
-    if ( !empty( $country_code ) ) {
68
-        $states = wpinv_get_country_states( $country_code );
67
+    if (!empty($country_code)) {
68
+        $states = wpinv_get_country_states($country_code);
69 69
         
70
-        $state = !empty( $states ) && isset( $states[$state_code] ) ? $states[$state_code] : $state;
70
+        $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state;
71 71
     }
72 72
 
73
-    return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code );
73
+    return apply_filters('wpinv_state_name', $state, $state_code, $country_code);
74 74
 }
75 75
 
76 76
 function wpinv_store_address() {
77
-    $address = wpinv_get_option( 'store_address', '' );
77
+    $address = wpinv_get_option('store_address', '');
78 78
 
79
-    return apply_filters( 'wpinv_store_address', $address );
79
+    return apply_filters('wpinv_store_address', $address);
80 80
 }
81 81
 
82
-function wpinv_get_user_address( $user_id = 0, $with_default = true ) {
82
+function wpinv_get_user_address($user_id = 0, $with_default = true) {
83 83
     global $wpi_userID;
84 84
     
85
-    if( empty( $user_id ) ) {
86
-        $user_id = !empty( $wpi_userID ) ? $wpi_userID : get_current_user_id();
85
+    if (empty($user_id)) {
86
+        $user_id = !empty($wpi_userID) ? $wpi_userID : get_current_user_id();
87 87
     }
88 88
     
89 89
     $address_fields = array(
@@ -101,29 +101,29 @@  discard block
 block discarded – undo
101 101
         'zip',
102 102
     );
103 103
     
104
-    $user_info = get_userdata( $user_id );
104
+    $user_info = get_userdata($user_id);
105 105
     
106 106
     $address = array();
107 107
     $address['user_id'] = $user_id;
108
-    $address['email'] = !empty( $user_info ) ? $user_info->user_email : '';
109
-    foreach ( $address_fields as $field ) {
110
-        $address[$field] = get_user_meta( $user_id, '_wpinv_' . $field, true );
108
+    $address['email'] = !empty($user_info) ? $user_info->user_email : '';
109
+    foreach ($address_fields as $field) {
110
+        $address[$field] = get_user_meta($user_id, '_wpinv_' . $field, true);
111 111
     }
112 112
 
113
-    if ( !empty( $user_info ) ) {
114
-        if( empty( $address['first_name'] ) )
113
+    if (!empty($user_info)) {
114
+        if (empty($address['first_name']))
115 115
             $address['first_name'] = $user_info->first_name;
116 116
         
117
-        if( empty( $address['last_name'] ) )
117
+        if (empty($address['last_name']))
118 118
             $address['last_name'] = $user_info->last_name;
119 119
     }
120 120
     
121
-    $address['name'] = trim( trim( $address['first_name'] . ' ' . $address['last_name'] ), "," );
121
+    $address['name'] = trim(trim($address['first_name'] . ' ' . $address['last_name']), ",");
122 122
     
123
-    if( empty( $address['state'] ) && $with_default )
123
+    if (empty($address['state']) && $with_default)
124 124
         $address['state'] = wpinv_get_default_state();
125 125
 
126
-    if( empty( $address['country'] ) && $with_default )
126
+    if (empty($address['country']) && $with_default)
127 127
         $address['country'] = wpinv_get_default_country();
128 128
 
129 129
 
@@ -137,16 +137,16 @@  discard block
 block discarded – undo
137 137
  * @param string $return What to return.
138 138
  * @return array
139 139
  */
140
-function wpinv_get_continents( $return = 'all' ) {
140
+function wpinv_get_continents($return = 'all') {
141 141
 
142
-    $continents = wpinv_get_data( 'continents' );
142
+    $continents = wpinv_get_data('continents');
143 143
 
144
-    switch( $return ) {
144
+    switch ($return) {
145 145
         case 'name' :
146
-            return wp_list_pluck( $continents, 'name' );
146
+            return wp_list_pluck($continents, 'name');
147 147
             break;
148 148
         case 'countries' :
149
-            return wp_list_pluck( $continents, 'countries' );
149
+            return wp_list_pluck($continents, 'countries');
150 150
             break;
151 151
         default :
152 152
             return $continents;
@@ -162,12 +162,12 @@  discard block
 block discarded – undo
162 162
  * @param string $country Country code. If no code is specified, defaults to the default country.
163 163
  * @return string
164 164
  */
165
-function wpinv_get_continent_code_for_country( $country = false ) {
165
+function wpinv_get_continent_code_for_country($country = false) {
166 166
 
167
-    $country = wpinv_sanitize_country( $country );
167
+    $country = wpinv_sanitize_country($country);
168 168
     
169
-	foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
170
-		if ( false !== array_search( $country, $countries, true ) ) {
169
+	foreach (wpinv_get_continents('countries') as $continent_code => $countries) {
170
+		if (false !== array_search($country, $countries, true)) {
171 171
 			return $continent_code;
172 172
 		}
173 173
 	}
@@ -183,13 +183,13 @@  discard block
 block discarded – undo
183 183
  * @param string $country Country code. If no code is specified, defaults to the default country.
184 184
  * @return array
185 185
  */
186
-function wpinv_get_country_calling_code( $country = null) {
186
+function wpinv_get_country_calling_code($country = null) {
187 187
 
188
-    $country = wpinv_sanitize_country( $country );
189
-    $codes   = wpinv_get_data( 'phone-codes' );
190
-    $code    = isset( $codes[ $country ] ) ? $codes[ $country ] : '';
188
+    $country = wpinv_sanitize_country($country);
189
+    $codes   = wpinv_get_data('phone-codes');
190
+    $code    = isset($codes[$country]) ? $codes[$country] : '';
191 191
 
192
-    if ( is_array( $code ) ) {
192
+    if (is_array($code)) {
193 193
         return $code[0];
194 194
     }
195 195
     return $code;
@@ -202,8 +202,8 @@  discard block
 block discarded – undo
202 202
  * @param bool $first_empty Whether or not the first item in the list should be empty
203 203
  * @return array
204 204
  */
205
-function wpinv_get_country_list( $first_empty = false ) {
206
-    return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty );
205
+function wpinv_get_country_list($first_empty = false) {
206
+    return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty);
207 207
 }
208 208
 
209 209
 /**
@@ -213,22 +213,22 @@  discard block
 block discarded – undo
213 213
  * @param bool $first_empty Whether or not the first item in the list should be empty
214 214
  * @return array
215 215
  */
216
-function wpinv_get_country_states( $country = null, $first_empty = false ) {
216
+function wpinv_get_country_states($country = null, $first_empty = false) {
217 217
     
218 218
     // Prepare the country.
219
-    $country = wpinv_sanitize_country( $country );
219
+    $country = wpinv_sanitize_country($country);
220 220
 
221 221
     // Fetch all states.
222
-    $all_states = wpinv_get_data( 'states' );
222
+    $all_states = wpinv_get_data('states');
223 223
 
224 224
     // Fetch the specified country's states.
225
-    $states     = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ;
226
-    $states     = apply_filters( "wpinv_{$country}_states", $states );
227
-    $states     = apply_filters( 'wpinv_country_states', $states, $country );
225
+    $states     = isset($all_states[$country]) ? $all_states[$country] : array();
226
+    $states     = apply_filters("wpinv_{$country}_states", $states);
227
+    $states     = apply_filters('wpinv_country_states', $states, $country);
228 228
 
229
-    asort( $states );
229
+    asort($states);
230 230
      
231
-    return wpinv_maybe_add_empty_option( $states, $first_empty );
231
+    return wpinv_maybe_add_empty_option($states, $first_empty);
232 232
 }
233 233
 
234 234
 /**
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
  * @return array
239 239
  */
240 240
 function wpinv_get_us_states_list() {
241
-    return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) );
241
+    return apply_filters('wpinv_usa_states', wpinv_get_country_states('US'));
242 242
 }
243 243
 
244 244
 /**
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
  * @return array
249 249
  */
250 250
 function wpinv_get_canada_states_list() {
251
-    return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) );
251
+    return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA'));
252 252
 }
253 253
 
254 254
 /**
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
  * @return array
259 259
  */
260 260
 function wpinv_get_australia_states_list() {
261
-    return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) );
261
+    return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU'));
262 262
 }
263 263
 
264 264
 /**
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
  * @return array
269 269
  */
270 270
 function wpinv_get_bangladesh_states_list() {
271
-    return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) );
271
+    return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD'));
272 272
 }
273 273
 
274 274
 /**
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
  * @return array
279 279
  */
280 280
 function wpinv_get_brazil_states_list() {
281
-    return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) );
281
+    return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR'));
282 282
 }
283 283
 
284 284
 /**
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
  * @return array
289 289
  */
290 290
 function wpinv_get_bulgaria_states_list() {
291
-    return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) );
291
+    return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG'));
292 292
 }
293 293
 
294 294
 /**
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
  * @return array
299 299
  */
300 300
 function wpinv_get_hong_kong_states_list() {
301
-    return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) );
301
+    return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK'));
302 302
 }
303 303
 
304 304
 /**
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
  * @return array
309 309
  */
310 310
 function wpinv_get_hungary_states_list() {
311
-    return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) );
311
+    return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU'));
312 312
 }
313 313
 
314 314
 /**
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
  * @return array
319 319
  */
320 320
 function wpinv_get_japan_states_list() {
321
-    return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) );
321
+    return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP'));
322 322
 }
323 323
 
324 324
 /**
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
  * @return array
329 329
  */
330 330
 function wpinv_get_china_states_list() {
331
-    return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) );
331
+    return apply_filters('wpinv_china_states', wpinv_get_country_states('CN'));
332 332
 }
333 333
 
334 334
 /**
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
  * @return array
339 339
  */
340 340
 function wpinv_get_new_zealand_states_list() {
341
-    return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) );
341
+    return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ'));
342 342
 }
343 343
 
344 344
 /**
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
  * @return array
349 349
  */
350 350
 function wpinv_get_peru_states_list() {
351
-    return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) );
351
+    return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE'));
352 352
 }
353 353
 
354 354
 /**
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
  * @return array
359 359
  */
360 360
 function wpinv_get_indonesia_states_list() {
361
-    return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) );
361
+    return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID'));
362 362
 }
363 363
 
364 364
 /**
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
  * @return array
369 369
  */
370 370
 function wpinv_get_india_states_list() {
371
-    return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) );
371
+    return apply_filters('wpinv_india_states', wpinv_get_country_states('IN'));
372 372
 }
373 373
 
374 374
 /**
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
  * @return array
379 379
  */
380 380
 function wpinv_get_iran_states_list() {
381
-    return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) );
381
+    return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR'));
382 382
 }
383 383
 
384 384
 /**
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
  * @return array
389 389
  */
390 390
 function wpinv_get_italy_states_list() {
391
-    return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) );
391
+    return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT'));
392 392
 }
393 393
 
394 394
 /**
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
  * @return array
399 399
  */
400 400
 function wpinv_get_malaysia_states_list() {
401
-    return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) );
401
+    return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY'));
402 402
 }
403 403
 
404 404
 /**
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
  * @return array
409 409
  */
410 410
 function wpinv_get_mexico_states_list() {
411
-    return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) );
411
+    return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX'));
412 412
 }
413 413
 
414 414
 /**
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
  * @return array
419 419
  */
420 420
 function wpinv_get_nepal_states_list() {
421
-    return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) );
421
+    return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP'));
422 422
 }
423 423
 
424 424
 /**
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
  * @return array
429 429
  */
430 430
 function wpinv_get_south_africa_states_list() {
431
-    return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) );
431
+    return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA'));
432 432
 }
433 433
 
434 434
 /**
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
  * @return array
439 439
  */
440 440
 function wpinv_get_thailand_states_list() {
441
-    return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) );
441
+    return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH'));
442 442
 }
443 443
 
444 444
 /**
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
  * @return array
449 449
  */
450 450
 function wpinv_get_turkey_states_list() {
451
-    return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) );
451
+    return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR'));
452 452
 }
453 453
 
454 454
 /**
@@ -458,28 +458,28 @@  discard block
 block discarded – undo
458 458
  * @return array
459 459
  */
460 460
 function wpinv_get_spain_states_list() {
461
-    return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) );
461
+    return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES'));
462 462
 }
463 463
 
464 464
 function wpinv_get_states_field() {
465
-	if( empty( $_POST['country'] ) ) {
465
+	if (empty($_POST['country'])) {
466 466
 		$_POST['country'] = wpinv_get_default_country();
467 467
 	}
468
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
468
+	$states = wpinv_get_country_states(sanitize_text_field($_POST['country']));
469 469
 
470
-	if( !empty( $states ) ) {
471
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
470
+	if (!empty($states)) {
471
+		$sanitized_field_name = sanitize_text_field($_POST['field_name']);
472 472
         
473 473
         $args = array(
474 474
 			'name'    => $sanitized_field_name,
475 475
 			'id'      => $sanitized_field_name,
476 476
 			'class'   => $sanitized_field_name . 'custom-select wpinv-select wpi_select2',
477
-			'options' => array_merge( array( '' => '' ), $states ),
477
+			'options' => array_merge(array('' => ''), $states),
478 478
 			'show_option_all'  => false,
479 479
 			'show_option_none' => false
480 480
 		);
481 481
 
482
-		$response = wpinv_html_select( $args );
482
+		$response = wpinv_html_select($args);
483 483
 
484 484
 	} else {
485 485
 		$response = 'nostates';
@@ -488,10 +488,10 @@  discard block
 block discarded – undo
488 488
 	return $response;
489 489
 }
490 490
 
491
-function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
492
-    $country = !empty( $country ) ? $country : wpinv_get_default_country();
491
+function wpinv_default_billing_country($country = '', $user_id = 0) {
492
+    $country = !empty($country) ? $country : wpinv_get_default_country();
493 493
     
494
-    return apply_filters( 'wpinv_default_billing_country', $country, $user_id );
494
+    return apply_filters('wpinv_default_billing_country', $country, $user_id);
495 495
 }
496 496
 
497 497
 /**
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
  */
504 504
 function wpinv_get_address_formats() {
505 505
 
506
-		return apply_filters( 'wpinv_localisation_address_formats',
506
+		return apply_filters('wpinv_localisation_address_formats',
507 507
 			array(
508 508
 				'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
509 509
 				'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
@@ -552,9 +552,9 @@  discard block
 block discarded – undo
552 552
  * @see `wpinv_get_invoice_address_replacements`
553 553
  * @return string
554 554
  */
555
-function wpinv_get_full_address_format( $country = false) {
555
+function wpinv_get_full_address_format($country = false) {
556 556
 
557
-    if( empty( $country ) ) {
557
+    if (empty($country)) {
558 558
         $country = wpinv_get_default_country();
559 559
     }
560 560
 
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 	$formats = wpinv_get_address_formats();
563 563
 
564 564
 	// Get format for the specified country.
565
-	$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
565
+	$format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default'];
566 566
     
567 567
     /**
568 568
 	 * Filters the address format to use on Invoices.
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
 	 * @param string $format  The address format to use.
575 575
      * @param string $country The country who's address format is being retrieved.
576 576
 	 */
577
-    return apply_filters( 'wpinv_get_full_address_format', $format, $country );
577
+    return apply_filters('wpinv_get_full_address_format', $format, $country);
578 578
 }
579 579
 
580 580
 /**
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
  * @param array $billing_details customer's billing details
586 586
  * @return array
587 587
  */
588
-function wpinv_get_invoice_address_replacements( $billing_details ) {
588
+function wpinv_get_invoice_address_replacements($billing_details) {
589 589
 
590 590
     $default_args = array(
591 591
         'address'           => '',
@@ -598,22 +598,22 @@  discard block
 block discarded – undo
598 598
 		'company'           => '',
599 599
     );
600 600
 
601
-    $args    = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' );
601
+    $args    = map_deep(wp_parse_args($billing_details, $default_args), 'trim');
602 602
     $state   = $args['state'];
603 603
     $country = $args['country'];
604 604
 
605 605
     // Handle full country name.
606
-    $full_country = empty( $country ) ? $country : wpinv_country_name( $country );
606
+    $full_country = empty($country) ? $country : wpinv_country_name($country);
607 607
 
608 608
     // Handle full state name.
609
-    $full_state   = ( $country && $state ) ?  wpinv_state_name( $state, $country ) : $state;
609
+    $full_state   = ($country && $state) ?  wpinv_state_name($state, $country) : $state;
610 610
 
611 611
     $args['postcode']    = $args['zip'];
612 612
     $args['name']        = $args['first_name'] . ' ' . $args['last_name'];
613 613
     $args['state']       = $full_state;
614 614
     $args['state_code']  = $state;
615 615
     $args['country']     = $full_country;
616
-    $args['country_code']= $country;
616
+    $args['country_code'] = $country;
617 617
 
618 618
     /**
619 619
 	 * Filters the address format replacements to use on Invoices.
@@ -624,14 +624,14 @@  discard block
 block discarded – undo
624 624
 	 * @param array $replacements  The address replacements to use.
625 625
      * @param array $billing_details  The billing details to use.
626 626
 	 */
627
-    $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details );
627
+    $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details);
628 628
 
629 629
     $return = array();
630 630
 
631
-    foreach( $replacements as $key => $value ) {
632
-        $value  = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : '';
631
+    foreach ($replacements as $key => $value) {
632
+        $value = is_scalar($value) ? trim(sanitize_text_field($value)) : '';
633 633
         $return['{{' . $key . '}}'] = $value;
634
-        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value );
634
+        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value);
635 635
     }
636 636
 
637 637
     return $return;
@@ -645,6 +645,6 @@  discard block
 block discarded – undo
645 645
  * @since 1.0.14
646 646
  * @return string
647 647
  */
648
-function wpinv_trim_formatted_address_line( $line ) {
649
-	return trim( $line, ', ' );
648
+function wpinv_trim_formatted_address_line($line) {
649
+	return trim($line, ', ');
650 650
 }
651 651
\ No newline at end of file
Please login to merge, or discard this patch.
templates/emails/wpinv-email-user_note.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if ( !defined('ABSPATH') ) {
4 4
     die('-1');
5
+}
5 6
 
6 7
 do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
7 8
 
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
6
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
7 7
 
8
-do_action( 'wpinv_email_before_note_details', $invoice, $email_type, $sent_to_admin, $customer_note );
8
+do_action('wpinv_email_before_note_details', $invoice, $email_type, $sent_to_admin, $customer_note);
9 9
 
10
-if ( ! empty( $message_body ) ) {
11
-    echo wpautop( wptexturize( $message_body ) );
10
+if (!empty($message_body)) {
11
+    echo wpautop(wptexturize($message_body));
12 12
 }
13 13
 
14
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
14
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
15 15
 
16
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
16
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
17 17
 
18
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
18
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
19 19
 
20
-do_action( 'wpinv_email_after_note_details', $invoice, $email_type, $sent_to_admin, $customer_note );
20
+do_action('wpinv_email_after_note_details', $invoice, $email_type, $sent_to_admin, $customer_note);
21 21
 
22
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
23 22
\ No newline at end of file
23
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
24 24
\ No newline at end of file
Please login to merge, or discard this patch.
templates/emails/wpinv-email-overdue.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if ( !defined('ABSPATH') ) {
4 4
     die('-1');
5
+}
5 6
 
6 7
 do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
7 8
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
6
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
7 7
 
8
-if ( ! empty( $message_body ) ) {
9
-    echo wpautop( wptexturize( $message_body ) );
8
+if (!empty($message_body)) {
9
+    echo wpautop(wptexturize($message_body));
10 10
 }
11 11
 
12
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
13 12
\ No newline at end of file
13
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
14 14
\ No newline at end of file
Please login to merge, or discard this patch.
templates/wpinv-invoice-print.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -1,41 +1,41 @@  discard block
 block discarded – undo
1 1
 <?php 
2
-if ( !defined('ABSPATH') ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit;
4 4
 }
5 5
 global $post;
6 6
 $invoice_id = $post->ID;
7
-$invoice = wpinv_get_invoice( $invoice_id );
8
-if ( empty( $invoice ) ) {
7
+$invoice = wpinv_get_invoice($invoice_id);
8
+if (empty($invoice)) {
9 9
     exit;
10 10
 }
11
-$type = $post->post_type == 'wpi_invoice' ? __( 'Invoice', 'invoicing' ): __( 'Quotation', 'invoicing' );
12
-do_action( 'wpinv_invoice_print_before_display', $invoice ); ?><!DOCTYPE html>
11
+$type = $post->post_type == 'wpi_invoice' ? __('Invoice', 'invoicing') : __('Quotation', 'invoicing');
12
+do_action('wpinv_invoice_print_before_display', $invoice); ?><!DOCTYPE html>
13 13
 <html <?php language_attributes(); ?>>
14 14
 <head>
15 15
     <meta charset="UTF-8">
16 16
     <title><?php wp_title() ?></title>
17
-    <meta charset="<?php bloginfo( 'charset' ); ?>" />
17
+    <meta charset="<?php bloginfo('charset'); ?>" />
18 18
     <meta name="viewport" content="width=device-width, initial-scale=1">
19 19
     <meta name="robots" content="noindex,nofollow">
20 20
 
21
-    <?php do_action( 'wpinv_invoice_print_head', $invoice ); ?>
21
+    <?php do_action('wpinv_invoice_print_head', $invoice); ?>
22 22
 </head>
23 23
 <body class="body wpinv wpinv-print">
24
-    <?php do_action( 'wpinv_invoice_print_body_start', $invoice ); ?>
24
+    <?php do_action('wpinv_invoice_print_body_start', $invoice); ?>
25 25
     <div class="container wpinv-wrap">
26
-        <?php if ( $watermark = wpinv_watermark( $invoice_id ) ) { ?>
27
-            <div class="watermark no-print"><p><?php echo esc_html( $watermark ) ?></p></div>
26
+        <?php if ($watermark = wpinv_watermark($invoice_id)) { ?>
27
+            <div class="watermark no-print"><p><?php echo esc_html($watermark) ?></p></div>
28 28
         <?php } ?>
29 29
         <!-- ///// Start PDF header -->
30 30
         <htmlpageheader name="wpinv-pdf-header">
31
-            <?php do_action( 'wpinv_invoice_print_before_header', $invoice ); ?>
31
+            <?php do_action('wpinv_invoice_print_before_header', $invoice); ?>
32 32
             <div class="row wpinv-header">
33 33
                 <div class="col-xs-6 wpinv-business">
34
-                    <a target="_blank" href="<?php echo esc_url( wpinv_get_business_website() ); ?>">
35
-                        <?php if ( $logo = wpinv_get_business_logo() ) { ?>
36
-                        <img class="logo" src="<?php echo esc_url( $logo ); ?>">
34
+                    <a target="_blank" href="<?php echo esc_url(wpinv_get_business_website()); ?>">
35
+                        <?php if ($logo = wpinv_get_business_logo()) { ?>
36
+                        <img class="logo" src="<?php echo esc_url($logo); ?>">
37 37
                         <?php } else { ?>
38
-                        <h1><?php echo esc_html( wpinv_get_business_name() ); ?></h1>
38
+                        <h1><?php echo esc_html(wpinv_get_business_name()); ?></h1>
39 39
                         <?php } ?>
40 40
                     </a>
41 41
                 </div>
@@ -44,56 +44,56 @@  discard block
 block discarded – undo
44 44
                     <h2><?php echo $type; ?></h2>
45 45
                 </div>
46 46
             </div>
47
-            <?php do_action( 'wpinv_invoice_print_after_header', $invoice ); ?>
47
+            <?php do_action('wpinv_invoice_print_after_header', $invoice); ?>
48 48
         </htmlpageheader>
49 49
         <!-- End PDF header ///// -->
50 50
         
51
-        <?php do_action( 'wpinv_invoice_print_before_top_content', $invoice ); ?>
51
+        <?php do_action('wpinv_invoice_print_before_top_content', $invoice); ?>
52 52
         <div class="row wpinv-top-content">
53 53
             <div class="col-xs-12 col-sm-6 wpinv-addresses">
54 54
                 <div class="col-xs-12 wpinv-address wpinv-from-address">
55 55
                     <?php wpinv_display_from_address(); ?>
56 56
                 </div>
57 57
                 <div class="col-xs-12 wpinv-address wpinv-to-address">
58
-                    <?php wpinv_display_to_address( $invoice_id ); ?>
58
+                    <?php wpinv_display_to_address($invoice_id); ?>
59 59
                 </div>
60 60
             </div>
61 61
             <div class="col-xs-12 col-sm-6 wpinv-details">
62 62
                 <div class="col-xs-12 wpinv-line-details">
63
-                    <?php do_action( 'wpinv_invoice_print_before_details', $invoice ); ?>
64
-                    <?php wpinv_display_invoice_details( $invoice ); ?>
65
-                    <?php do_action( 'wpinv_invoice_print_after_details', $invoice ); ?>
63
+                    <?php do_action('wpinv_invoice_print_before_details', $invoice); ?>
64
+                    <?php wpinv_display_invoice_details($invoice); ?>
65
+                    <?php do_action('wpinv_invoice_print_after_details', $invoice); ?>
66 66
                 </div>
67 67
             </div>
68 68
         </div>
69
-        <?php do_action( 'wpinv_invoice_print_after_top_content', $invoice ); ?>
69
+        <?php do_action('wpinv_invoice_print_after_top_content', $invoice); ?>
70 70
 
71
-        <?php do_action( 'wpinv_invoice_print_middle', $invoice ); ?>
71
+        <?php do_action('wpinv_invoice_print_middle', $invoice); ?>
72 72
         
73
-        <?php do_action( 'wpinv_invoice_print_before_line_items', $invoice ); ?>
73
+        <?php do_action('wpinv_invoice_print_before_line_items', $invoice); ?>
74 74
         <div class="row wpinv-items">
75 75
             <div class="col-sm-12 wpinv-line-items">
76
-                <?php wpinv_display_line_items( $invoice_id ); ?>
76
+                <?php wpinv_display_line_items($invoice_id); ?>
77 77
             </div>
78 78
         </div>
79
-        <?php do_action( 'wpinv_invoice_print_after_line_items', $invoice ); ?>
79
+        <?php do_action('wpinv_invoice_print_after_line_items', $invoice); ?>
80 80
         
81 81
         <!-- ///// Start PDF footer -->
82 82
         <htmlpagefooter name="wpinv-pdf-footer">
83
-            <?php do_action( 'wpinv_invoice_print_before_footer', $invoice ); ?>
83
+            <?php do_action('wpinv_invoice_print_before_footer', $invoice); ?>
84 84
             <div class="row wpinv-footer">
85 85
                 <div class="col-sm-12">
86
-                    <?php if ( $term_text = wpinv_get_terms_text() ) { ?>
87
-                    <div class="terms-text"><?php echo wpautop( $term_text ); ?></div>
86
+                    <?php if ($term_text = wpinv_get_terms_text()) { ?>
87
+                    <div class="terms-text"><?php echo wpautop($term_text); ?></div>
88 88
                     <?php } ?>
89 89
                     <div class="footer-text"><?php echo wpinv_get_business_footer(); ?></div>
90
-                    <div class="print-only"><?php _e( 'Page ', 'invoicing' ) ?> {PAGENO}/{nbpg}</div>
90
+                    <div class="print-only"><?php _e('Page ', 'invoicing') ?> {PAGENO}/{nbpg}</div>
91 91
                 </div>
92 92
             </div>
93
-            <?php do_action( 'wpinv_invoice_print_after_footer', $invoice ); ?>
93
+            <?php do_action('wpinv_invoice_print_after_footer', $invoice); ?>
94 94
         </htmlpagefooter>
95 95
         <!-- End PDF footer ///// -->
96 96
     </div><!-- END wpinv-wrap -->
97
-    <?php do_action( 'wpinv_invoice_print_body_end', $invoice ); ?>
97
+    <?php do_action('wpinv_invoice_print_body_end', $invoice); ?>
98 98
 </body>
99 99
 </html>
100 100
\ No newline at end of file
Please login to merge, or discard this patch.
templates/wpinv-invoice-history.php 3 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 if ( !( $user_id = get_current_user_id() ) ) {
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
 		<tbody>
32 32
 			<?php foreach ( $user_invoices->invoices as $invoice ) {
33
-				?>
33
+                ?>
34 34
 				<tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>">
35 35
 					<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
36 36
 						<td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>">
@@ -53,31 +53,31 @@  discard block
 block discarded – undo
53 53
 
54 54
 							<?php elseif ( 'invoice-actions' === $column_id ) : ?>
55 55
 								<?php
56
-									$actions = array(
57
-										'pay'    => array(
58
-											'url'  => $invoice->get_checkout_payment_url(),
59
-											'name' => __( 'Pay Now', 'invoicing' ),
56
+                                    $actions = array(
57
+                                        'pay'    => array(
58
+                                            'url'  => $invoice->get_checkout_payment_url(),
59
+                                            'name' => __( 'Pay Now', 'invoicing' ),
60 60
                                             'class' => 'btn-success'
61
-										),
61
+                                        ),
62 62
                                         'print'   => array(
63
-											'url'  => $invoice->get_view_url(),
64
-											'name' => __( 'Print', 'invoicing' ),
63
+                                            'url'  => $invoice->get_view_url(),
64
+                                            'name' => __( 'Print', 'invoicing' ),
65 65
                                             'class' => 'btn-primary',
66 66
                                             'attrs' => 'target="_blank"'
67
-										)
68
-									);
67
+                                        )
68
+                                    );
69 69
 
70
-									if ( ! $invoice->needs_payment() ) {
71
-										unset( $actions['pay'] );
72
-									}
70
+                                    if ( ! $invoice->needs_payment() ) {
71
+                                        unset( $actions['pay'] );
72
+                                    }
73 73
 
74
-									if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) {
75
-										foreach ( $actions as $key => $action ) {
76
-											$class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
74
+                                    if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) {
75
+                                        foreach ( $actions as $key => $action ) {
76
+                                            $class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
77 77
                                             echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
78
-										}
79
-									}
80
-								?>
78
+                                        }
79
+                                    }
80
+                                ?>
81 81
 							<?php endif; ?>
82 82
 						</td>
83 83
 					<?php endforeach; ?>
@@ -91,22 +91,22 @@  discard block
 block discarded – undo
91 91
 	<?php if ( 1 < $user_invoices->max_num_pages ) : ?>
92 92
 		<div class="invoicing-Pagination">
93 93
 			<?php
94
-			$big = 999999;
95
-
96
-			if (get_query_var('paged'))
97
-				$current_page = get_query_var('paged');
98
-			elseif (get_query_var('page'))
99
-				$current_page = get_query_var('page');
100
-			else
101
-				$current_page = 1;
102
-
103
-			echo paginate_links( array(
104
-				'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
105
-				'format'  => '?paged=%#%',
106
-				'current' => max( 1, $current_page ),
107
-				'total'   => $user_invoices->max_num_pages,
108
-			) );
109
-			?>
94
+            $big = 999999;
95
+
96
+            if (get_query_var('paged'))
97
+                $current_page = get_query_var('paged');
98
+            elseif (get_query_var('page'))
99
+                $current_page = get_query_var('page');
100
+            else
101
+                $current_page = 1;
102
+
103
+            echo paginate_links( array(
104
+                'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
105
+                'format'  => '?paged=%#%',
106
+                'current' => max( 1, $current_page ),
107
+                'total'   => $user_invoices->max_num_pages,
108
+            ) );
109
+            ?>
110 110
 		</div>
111 111
 	<?php endif; ?>
112 112
 
Please login to merge, or discard this patch.
Braces   +7 added lines, -6 removed lines patch added patch discarded remove patch
@@ -93,12 +93,13 @@
 block discarded – undo
93 93
 			<?php
94 94
 			$big = 999999;
95 95
 
96
-			if (get_query_var('paged'))
97
-				$current_page = get_query_var('paged');
98
-			elseif (get_query_var('page'))
99
-				$current_page = get_query_var('page');
100
-			else
101
-				$current_page = 1;
96
+			if (get_query_var('paged')) {
97
+							$current_page = get_query_var('paged');
98
+			} elseif (get_query_var('page')) {
99
+							$current_page = get_query_var('page');
100
+			} else {
101
+							$current_page = 1;
102
+			}
102 103
 
103 104
 			echo paginate_links( array(
104 105
 				'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -1,83 +1,83 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6
-if ( !( $user_id = get_current_user_id() ) ) {
6
+if (!($user_id = get_current_user_id())) {
7 7
     ?>
8
-    <div class="wpinv-empty alert alert-error"><?php _e( 'You are not allowed to access this section', 'invoicing' ) ;?></div>
8
+    <div class="wpinv-empty alert alert-error"><?php _e('You are not allowed to access this section', 'invoicing'); ?></div>
9 9
     <?php
10 10
     return;
11 11
 }
12 12
 
13 13
 global $current_page;
14
-$current_page   = empty( $current_page ) ? 1 : absint( $current_page );
15
-$query          = apply_filters( 'wpinv_user_invoices_query', array( 'user' => $user_id, 'page' => $current_page, 'paginate' => true, 'orderby' => 'invoice_date' ) );
16
-$user_invoices  = wpinv_get_invoices( $query );
14
+$current_page   = empty($current_page) ? 1 : absint($current_page);
15
+$query          = apply_filters('wpinv_user_invoices_query', array('user' => $user_id, 'page' => $current_page, 'paginate' => true, 'orderby' => 'invoice_date'));
16
+$user_invoices  = wpinv_get_invoices($query);
17 17
 $has_invoices   = 0 < $user_invoices->total;
18 18
     
19
-do_action( 'wpinv_before_user_invoices', $has_invoices ); ?>
19
+do_action('wpinv_before_user_invoices', $has_invoices); ?>
20 20
 
21
-<?php if ( $has_invoices ) { ?>
21
+<?php if ($has_invoices) { ?>
22 22
 	<table class="table table-bordered table-hover table-responsive wpi-user-invoices">
23 23
 		<thead>
24 24
 			<tr>
25
-				<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
26
-					<th class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>"><span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span></th>
25
+				<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
26
+					<th class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>"><span class="nobr"><?php echo esc_html($column_name['title']); ?></span></th>
27 27
 				<?php endforeach; ?>
28 28
 			</tr>
29 29
 		</thead>
30 30
 
31 31
 		<tbody>
32
-			<?php foreach ( $user_invoices->invoices as $invoice ) {
32
+			<?php foreach ($user_invoices->invoices as $invoice) {
33 33
 				?>
34 34
 				<tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>">
35
-					<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
36
-						<td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>">
37
-							<?php if ( has_action( 'wpinv_user_invoices_column_' . $column_id ) ) : ?>
38
-								<?php do_action( 'wpinv_user_invoices_column_' . $column_id, $invoice ); ?>
39
-
40
-							<?php elseif ( 'invoice-number' === $column_id ) : ?>
41
-								<a href="<?php echo esc_url( $invoice->get_view_url() ); ?>">
42
-									<?php echo _x( '#', 'hash before invoice number', 'invoicing' ) . $invoice->get_number(); ?>
35
+					<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
36
+						<td class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>" data-title="<?php echo esc_attr($column_name['title']); ?>">
37
+							<?php if (has_action('wpinv_user_invoices_column_' . $column_id)) : ?>
38
+								<?php do_action('wpinv_user_invoices_column_' . $column_id, $invoice); ?>
39
+
40
+							<?php elseif ('invoice-number' === $column_id) : ?>
41
+								<a href="<?php echo esc_url($invoice->get_view_url()); ?>">
42
+									<?php echo _x('#', 'hash before invoice number', 'invoicing') . $invoice->get_number(); ?>
43 43
 								</a>
44 44
 
45
-							<?php elseif ( 'created-date' === $column_id ) : $date = wpinv_get_date_created( $invoice->ID ); $dateYMD = wpinv_get_date_created( $invoice->ID, 'Y-m-d H:i:s' ); ?>
46
-								<time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
45
+							<?php elseif ('created-date' === $column_id) : $date = wpinv_get_date_created($invoice->ID); $dateYMD = wpinv_get_date_created($invoice->ID, 'Y-m-d H:i:s'); ?>
46
+								<time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
47 47
 
48
-							<?php elseif ( 'payment-date' === $column_id ) : $date = wpinv_get_invoice_date( $invoice->ID, '', false ); $dateYMD = wpinv_get_invoice_date( $invoice->ID, 'Y-m-d H:i:s', false ); ?>
49
-								<time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
48
+							<?php elseif ('payment-date' === $column_id) : $date = wpinv_get_invoice_date($invoice->ID, '', false); $dateYMD = wpinv_get_invoice_date($invoice->ID, 'Y-m-d H:i:s', false); ?>
49
+								<time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
50 50
 
51
-							<?php elseif ( 'invoice-status' === $column_id ) : ?>
52
-								<?php echo wpinv_invoice_status_label( $invoice_status, $invoice->get_status( true ) ) ; ?>
51
+							<?php elseif ('invoice-status' === $column_id) : ?>
52
+								<?php echo wpinv_invoice_status_label($invoice_status, $invoice->get_status(true)); ?>
53 53
 
54
-							<?php elseif ( 'invoice-total' === $column_id ) : ?>
55
-								<?php echo $invoice->get_total( true ); ?>
54
+							<?php elseif ('invoice-total' === $column_id) : ?>
55
+								<?php echo $invoice->get_total(true); ?>
56 56
 
57
-							<?php elseif ( 'invoice-actions' === $column_id ) : ?>
57
+							<?php elseif ('invoice-actions' === $column_id) : ?>
58 58
 								<?php
59 59
 									$actions = array(
60 60
 										'pay'    => array(
61 61
 											'url'  => $invoice->get_checkout_payment_url(),
62
-											'name' => __( 'Pay Now', 'invoicing' ),
62
+											'name' => __('Pay Now', 'invoicing'),
63 63
                                             'class' => 'btn-success'
64 64
 										),
65 65
                                         'print'   => array(
66 66
 											'url'  => $invoice->get_view_url(),
67
-											'name' => __( 'Print', 'invoicing' ),
67
+											'name' => __('Print', 'invoicing'),
68 68
                                             'class' => 'btn-primary',
69 69
                                             'attrs' => 'target="_blank"'
70 70
 										)
71 71
 									);
72 72
 
73
-									if ( ! $invoice->needs_payment() ) {
74
-										unset( $actions['pay'] );
73
+									if (!$invoice->needs_payment()) {
74
+										unset($actions['pay']);
75 75
 									}
76 76
 
77
-									if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) {
78
-										foreach ( $actions as $key => $action ) {
77
+									if ($actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice)) {
78
+										foreach ($actions as $key => $action) {
79 79
 											$class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
80
-                                            echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
80
+                                            echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>';
81 81
 										}
82 82
 									}
83 83
 								?>
@@ -89,9 +89,9 @@  discard block
 block discarded – undo
89 89
 		</tbody>
90 90
 	</table>
91 91
 
92
-	<?php do_action( 'wpinv_before_user_invoices_pagination' ); ?>
92
+	<?php do_action('wpinv_before_user_invoices_pagination'); ?>
93 93
 
94
-	<?php if ( 1 < $user_invoices->max_num_pages ) : ?>
94
+	<?php if (1 < $user_invoices->max_num_pages) : ?>
95 95
 		<div class="invoicing-Pagination">
96 96
 			<?php
97 97
 			$big = 999999;
@@ -103,20 +103,20 @@  discard block
 block discarded – undo
103 103
 			else
104 104
 				$current_page = 1;
105 105
 
106
-			echo paginate_links( array(
107
-				'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
106
+			echo paginate_links(array(
107
+				'base'    => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
108 108
 				'format'  => '?paged=%#%',
109
-				'current' => max( 1, $current_page ),
109
+				'current' => max(1, $current_page),
110 110
 				'total'   => $user_invoices->max_num_pages,
111
-			) );
111
+			));
112 112
 			?>
113 113
 		</div>
114 114
 	<?php endif; ?>
115 115
 
116 116
 <?php } else { ?>
117 117
 	<div class="wpinv-empty alert-info">
118
-		<?php _e( 'No invoice has been made yet.', 'invoicing' ); ?>
118
+		<?php _e('No invoice has been made yet.', 'invoicing'); ?>
119 119
 	</div>
120 120
 <?php } ?>
121 121
 
122
-<?php do_action( 'wpinv_after_user_invoices', $has_invoices ); ?>
122
+<?php do_action('wpinv_after_user_invoices', $has_invoices); ?>
Please login to merge, or discard this patch.
templates/wpinv-invalid-access.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -1,56 +1,56 @@
 block discarded – undo
1 1
 <?php 
2
-if ( !defined('ABSPATH') ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit;
4 4
 }
5
-do_action( 'wpinv_invalid_invoice_before_display' ); ?><!DOCTYPE html>
5
+do_action('wpinv_invalid_invoice_before_display'); ?><!DOCTYPE html>
6 6
 <html <?php language_attributes(); ?>>
7 7
 <head>
8 8
     <meta charset="UTF-8">
9 9
     <title><?php wp_title() ?></title>
10
-    <meta charset="<?php bloginfo( 'charset' ); ?>" />
10
+    <meta charset="<?php bloginfo('charset'); ?>" />
11 11
     <meta name="viewport" content="width=device-width,initial-scale=1">
12 12
     <meta name="robots" content="noindex,nofollow">
13
-    <?php do_action( 'wpinv_invalid_invoice_head' ); ?>
13
+    <?php do_action('wpinv_invalid_invoice_head'); ?>
14 14
 </head>
15 15
 <body class="body wpinv wpinv-print wpinv-invalid-invoice">
16
-    <?php do_action( 'wpinv_invalid_invoice_body_start' ); ?>
16
+    <?php do_action('wpinv_invalid_invoice_body_start'); ?>
17 17
     <div class="container wpinv-wrap">
18 18
         <!-- ///// Start Header -->
19 19
         <htmlpageheader name="wpinv-pdf-header">
20
-            <?php do_action( 'wpinv_invalid_invoice_before_header' ); ?>
20
+            <?php do_action('wpinv_invalid_invoice_before_header'); ?>
21 21
             <div class="row wpinv-header">
22 22
                 <div class="col-xs-12 wpinv-business">
23
-                    <a target="_blank" href="<?php echo esc_url( wpinv_get_business_website() ); ?>">
24
-                        <?php if ( $logo = wpinv_get_business_logo() ) { ?>
25
-                        <img class="logo" src="<?php echo esc_url( $logo ); ?>">
23
+                    <a target="_blank" href="<?php echo esc_url(wpinv_get_business_website()); ?>">
24
+                        <?php if ($logo = wpinv_get_business_logo()) { ?>
25
+                        <img class="logo" src="<?php echo esc_url($logo); ?>">
26 26
                         <?php } else { ?>
27
-                        <h1><?php echo esc_html( wpinv_get_business_name() ); ?></h1>
27
+                        <h1><?php echo esc_html(wpinv_get_business_name()); ?></h1>
28 28
                         <?php } ?>
29 29
                     </a>
30 30
                 </div>
31 31
             </div>
32
-            <?php do_action( 'wpinv_invalid_invoice_after_header' ); ?>
32
+            <?php do_action('wpinv_invalid_invoice_after_header'); ?>
33 33
         </htmlpageheader>
34 34
         <!-- End Header ///// -->
35 35
         
36
-        <?php do_action( 'wpinv_invalid_invoice_before_content' ); ?>
36
+        <?php do_action('wpinv_invalid_invoice_before_content'); ?>
37 37
 
38
-        <?php do_action( 'wpinv_invalid_invoice_content' ); ?>
38
+        <?php do_action('wpinv_invalid_invoice_content'); ?>
39 39
         
40
-        <?php do_action( 'wpinv_invalid_invoice_after_content' ); ?>
40
+        <?php do_action('wpinv_invalid_invoice_after_content'); ?>
41 41
         
42 42
         <!-- ///// Start Footer -->
43 43
         <htmlpagefooter name="wpinv-pdf-footer">
44
-            <?php do_action( 'wpinv_invalid_invoice_before_footer' ); ?>
44
+            <?php do_action('wpinv_invalid_invoice_before_footer'); ?>
45 45
             <div class="row wpinv-footer">
46 46
                 <div class="col-sm-12">
47 47
                     <div class="footer-text"><?php echo wpinv_get_business_footer(); ?></div>
48 48
                 </div>
49 49
             </div>
50
-            <?php do_action( 'wpinv_invalid_invoice_after_footer' ); ?>
50
+            <?php do_action('wpinv_invalid_invoice_after_footer'); ?>
51 51
         </htmlpagefooter>
52 52
         <!-- End Footer ///// -->
53 53
     </div>
54
-    <?php do_action( 'wpinv_invalid_invoice_body_end' ); ?>
54
+    <?php do_action('wpinv_invalid_invoice_body_end'); ?>
55 55
 </body>
56 56
 </html>
57 57
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-subscriptions-db.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly.
3
-if (!defined( 'ABSPATH' ) ) exit;
3
+if (!defined( 'ABSPATH' ) ) {
4
+    exit;
5
+}
4 6
 
5 7
 /**
6 8
  * The Subscriptions DB Class
Please login to merge, or discard this patch.
Spacing   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly.
3
-if (!defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 /**
6 6
  * The Subscriptions DB Class
@@ -68,8 +68,8 @@  discard block
 block discarded – undo
68 68
             'transaction_id'    => '',
69 69
             'parent_payment_id' => 0,
70 70
             'product_id'        => 0,
71
-            'created'           => date( 'Y-m-d H:i:s' ),
72
-            'expiration'        => date( 'Y-m-d H:i:s' ),
71
+            'created'           => date('Y-m-d H:i:s'),
72
+            'expiration'        => date('Y-m-d H:i:s'),
73 73
             'trial_period'      => '',
74 74
             'status'            => '',
75 75
             'profile_id'        => '',
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
      * @access  public
83 83
      * @since   1.0.0
84 84
      */
85
-    public function get_subscriptions( $args = array() ) {
85
+    public function get_subscriptions($args = array()) {
86 86
         global $wpdb;
87 87
 
88 88
         $defaults = array(
89
-            'number'       => get_option( 'posts_per_page' ),
89
+            'number'       => get_option('posts_per_page'),
90 90
             'offset'       => 0,
91 91
             'search'       => '',
92 92
             'customer_id'  => 0,
@@ -94,21 +94,21 @@  discard block
 block discarded – undo
94 94
             'order'        => 'DESC'
95 95
         );
96 96
 
97
-        $args  = wp_parse_args( $args, $defaults );
97
+        $args = wp_parse_args($args, $defaults);
98 98
 
99
-        if( $args['number'] < 1 ) {
99
+        if ($args['number'] < 1) {
100 100
             $args['number'] = 999999999999;
101 101
         }
102 102
 
103 103
         $where = ' WHERE 1=1 ';
104 104
 
105 105
         // specific customers
106
-        if( ! empty( $args['id'] ) ) {
106
+        if (!empty($args['id'])) {
107 107
 
108
-            if( is_array( $args['id'] ) ) {
109
-                $ids = implode( ',', array_map('intval', $args['id'] ) );
108
+            if (is_array($args['id'])) {
109
+                $ids = implode(',', array_map('intval', $args['id']));
110 110
             } else {
111
-                $ids = intval( $args['id'] );
111
+                $ids = intval($args['id']);
112 112
             }
113 113
 
114 114
             $where .= " AND `id` IN( {$ids} ) ";
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
         }
117 117
 
118 118
         // Specific products
119
-        if( ! empty( $args['product_id'] ) ) {
119
+        if (!empty($args['product_id'])) {
120 120
 
121
-            if( is_array( $args['product_id'] ) ) {
122
-                $product_ids = implode( ',', array_map('intval', $args['product_id'] ) );
121
+            if (is_array($args['product_id'])) {
122
+                $product_ids = implode(',', array_map('intval', $args['product_id']));
123 123
             } else {
124
-                $product_ids = intval( $args['product_id'] );
124
+                $product_ids = intval($args['product_id']);
125 125
             }
126 126
 
127 127
             $where .= " AND `product_id` IN( {$product_ids} ) ";
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
         }
130 130
 
131 131
         // Specific parent payments
132
-        if( ! empty( $args['parent_payment_id'] ) ) {
132
+        if (!empty($args['parent_payment_id'])) {
133 133
 
134
-            if( is_array( $args['parent_payment_id'] ) ) {
135
-                $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) );
134
+            if (is_array($args['parent_payment_id'])) {
135
+                $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id']));
136 136
             } else {
137
-                $parent_payment_ids = intval( $args['parent_payment_id'] );
137
+                $parent_payment_ids = intval($args['parent_payment_id']);
138 138
             }
139 139
 
140 140
             $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) ";
@@ -142,12 +142,12 @@  discard block
 block discarded – undo
142 142
         }
143 143
 
144 144
         // Specific transaction IDs
145
-        if( ! empty( $args['transaction_id'] ) ) {
145
+        if (!empty($args['transaction_id'])) {
146 146
 
147
-            if( is_array( $args['transaction_id'] ) ) {
148
-                $transaction_ids = implode( "','", array_map('sanitize_text_field', $args['transaction_id'] ) );
147
+            if (is_array($args['transaction_id'])) {
148
+                $transaction_ids = implode("','", array_map('sanitize_text_field', $args['transaction_id']));
149 149
             } else {
150
-                $transaction_ids = sanitize_text_field( $args['transaction_id'] );
150
+                $transaction_ids = sanitize_text_field($args['transaction_id']);
151 151
             }
152 152
 
153 153
             $where .= " AND `transaction_id` IN ( '{$transaction_ids}' ) ";
@@ -155,12 +155,12 @@  discard block
 block discarded – undo
155 155
         }
156 156
 
157 157
         // Subscriptoins for specific customers
158
-        if( ! empty( $args['customer_id'] ) ) {
158
+        if (!empty($args['customer_id'])) {
159 159
 
160
-            if( is_array( $args['customer_id'] ) ) {
161
-                $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) );
160
+            if (is_array($args['customer_id'])) {
161
+                $customer_ids = implode(',', array_map('intval', $args['customer_id']));
162 162
             } else {
163
-                $customer_ids = intval( $args['customer_id'] );
163
+                $customer_ids = intval($args['customer_id']);
164 164
             }
165 165
 
166 166
             $where .= " AND `customer_id` IN( {$customer_ids} ) ";
@@ -168,12 +168,12 @@  discard block
 block discarded – undo
168 168
         }
169 169
 
170 170
         // Subscriptions for specific profile IDs
171
-        if( ! empty( $args['profile_id'] ) ) {
171
+        if (!empty($args['profile_id'])) {
172 172
 
173
-            if( is_array( $args['profile_id'] ) ) {
174
-                $profile_ids = implode( "','", array_map('sanitize_text_field', $args['profile_id'] ) );
173
+            if (is_array($args['profile_id'])) {
174
+                $profile_ids = implode("','", array_map('sanitize_text_field', $args['profile_id']));
175 175
             } else {
176
-                $profile_ids = sanitize_text_field( $args['profile_id'] );
176
+                $profile_ids = sanitize_text_field($args['profile_id']);
177 177
             }
178 178
 
179 179
             $where .= " AND `profile_id` IN( '{$profile_ids}' ) ";
@@ -181,12 +181,12 @@  discard block
 block discarded – undo
181 181
         }
182 182
 
183 183
         // Subscriptions for specific statuses
184
-        if( ! empty( $args['status'] ) ) {
184
+        if (!empty($args['status'])) {
185 185
 
186
-            if( is_array( $args['status'] ) ) {
187
-                $statuses = implode( "','", array_map( 'sanitize_text_field', $args['status'] ) );
186
+            if (is_array($args['status'])) {
187
+                $statuses = implode("','", array_map('sanitize_text_field', $args['status']));
188 188
             } else {
189
-                $statuses = sanitize_text_field( $args['status'] );
189
+                $statuses = sanitize_text_field($args['status']);
190 190
             }
191 191
 
192 192
             $where .= " AND `status` IN( '{$statuses}' ) ";
@@ -194,21 +194,21 @@  discard block
 block discarded – undo
194 194
         }
195 195
 
196 196
         // Subscriptions created for a specific date or in a date range
197
-        if( ! empty( $args['date'] ) ) {
197
+        if (!empty($args['date'])) {
198 198
 
199
-            if( is_array( $args['date'] ) ) {
199
+            if (is_array($args['date'])) {
200 200
 
201
-                if( ! empty( $args['date']['start'] ) ) {
201
+                if (!empty($args['date']['start'])) {
202 202
 
203
-                    $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
203
+                    $start = date('Y-m-d H:i:s', strtotime($args['date']['start']));
204 204
 
205 205
                     $where .= " AND `created` >= '{$start}'";
206 206
 
207 207
                 }
208 208
 
209
-                if( ! empty( $args['date']['end'] ) ) {
209
+                if (!empty($args['date']['end'])) {
210 210
 
211
-                    $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
211
+                    $end = date('Y-m-d H:i:s', strtotime($args['date']['end']));
212 212
 
213 213
                     $where .= " AND `created` <= '{$end}'";
214 214
 
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
 
217 217
             } else {
218 218
 
219
-                $year  = date( 'Y', strtotime( $args['date'] ) );
220
-                $month = date( 'm', strtotime( $args['date'] ) );
221
-                $day   = date( 'd', strtotime( $args['date'] ) );
219
+                $year  = date('Y', strtotime($args['date']));
220
+                $month = date('m', strtotime($args['date']));
221
+                $day   = date('d', strtotime($args['date']));
222 222
 
223 223
                 $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )";
224 224
             }
@@ -226,21 +226,21 @@  discard block
 block discarded – undo
226 226
         }
227 227
 
228 228
         // Subscriptions with a specific expiration date or in an expiration date range
229
-        if( ! empty( $args['expiration'] ) ) {
229
+        if (!empty($args['expiration'])) {
230 230
 
231
-            if( is_array( $args['expiration'] ) ) {
231
+            if (is_array($args['expiration'])) {
232 232
 
233
-                if( ! empty( $args['expiration']['start'] ) ) {
233
+                if (!empty($args['expiration']['start'])) {
234 234
 
235
-                    $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) );
235
+                    $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start']));
236 236
 
237 237
                     $where .= " AND `expiration` >= '{$start}'";
238 238
 
239 239
                 }
240 240
 
241
-                if( ! empty( $args['expiration']['end'] ) ) {
241
+                if (!empty($args['expiration']['end'])) {
242 242
 
243
-                    $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) );
243
+                    $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end']));
244 244
 
245 245
                     $where .= " AND `expiration` <= '{$end}'";
246 246
 
@@ -248,73 +248,73 @@  discard block
 block discarded – undo
248 248
 
249 249
             } else {
250 250
 
251
-                $year  = date( 'Y', strtotime( $args['expiration'] ) );
252
-                $month = date( 'm', strtotime( $args['expiration'] ) );
253
-                $day   = date( 'd', strtotime( $args['expiration'] ) );
251
+                $year  = date('Y', strtotime($args['expiration']));
252
+                $month = date('m', strtotime($args['expiration']));
253
+                $day   = date('d', strtotime($args['expiration']));
254 254
 
255 255
                 $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )";
256 256
             }
257 257
 
258 258
         }
259 259
 
260
-        if ( ! empty( $args['search'] ) ) {
260
+        if (!empty($args['search'])) {
261 261
 
262
-            if( false !== strpos( 'id:', $args['search'] ) ) {
262
+            if (false !== strpos('id:', $args['search'])) {
263 263
 
264
-                $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) );
265
-                $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'";
264
+                $args['search'] = trim(str_replace('id:', '', $args['search']));
265
+                $where .= " AND `id` = '" . esc_sql($args['search']) . "'";
266 266
 
267
-            } else if( false !== strpos( $args['search'], 'txn:' ) ) {
267
+            } else if (false !== strpos($args['search'], 'txn:')) {
268 268
 
269
-                $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) );
270
-                $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'";
269
+                $args['search'] = trim(str_replace('txn:', '', $args['search']));
270
+                $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'";
271 271
 
272
-            } else if( false !== strpos( $args['search'], 'profile_id:' ) ) {
272
+            } else if (false !== strpos($args['search'], 'profile_id:')) {
273 273
 
274
-                $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) );
275
-                $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'";
274
+                $args['search'] = trim(str_replace('profile_id:', '', $args['search']));
275
+                $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'";
276 276
 
277
-            } else if( false !== strpos( $args['search'], 'product_id:' ) ) {
277
+            } else if (false !== strpos($args['search'], 'product_id:')) {
278 278
 
279
-                $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) );
280
-                $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'";
279
+                $args['search'] = trim(str_replace('product_id:', '', $args['search']));
280
+                $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'";
281 281
 
282
-            } else if( false !== strpos( $args['search'], 'customer_id:' ) ) {
282
+            } else if (false !== strpos($args['search'], 'customer_id:')) {
283 283
 
284
-                $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) );
285
-                $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'";
284
+                $args['search'] = trim(str_replace('customer_id:', '', $args['search']));
285
+                $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'";
286 286
 
287 287
             } else {
288 288
 
289
-                $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )";
289
+                $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )";
290 290
 
291 291
             }
292 292
 
293 293
         }
294 294
 
295
-        $args['orderby'] = ! array_key_exists( $args['orderby'], $this->get_columns() ) ? 'id' : $args['orderby'];
295
+        $args['orderby'] = !array_key_exists($args['orderby'], $this->get_columns()) ? 'id' : $args['orderby'];
296 296
 
297
-        if( 'amount' == $args['orderby'] ) {
297
+        if ('amount' == $args['orderby']) {
298 298
             $args['orderby'] = 'amount+0';
299 299
         }
300 300
 
301
-        $cache_key = md5( 'wpinv_subscriptions_' . serialize( $args ) );
301
+        $cache_key = md5('wpinv_subscriptions_' . serialize($args));
302 302
 
303
-        $subscriptions = wp_cache_get( $cache_key, 'subscriptions' );
303
+        $subscriptions = wp_cache_get($cache_key, 'subscriptions');
304 304
 
305
-        $args['orderby'] = esc_sql( $args['orderby'] );
306
-        $args['order']   = esc_sql( $args['order'] );
305
+        $args['orderby'] = esc_sql($args['orderby']);
306
+        $args['order']   = esc_sql($args['order']);
307 307
 
308
-        if( $subscriptions === false ) {
309
-            $subscriptions = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM  $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint( $args['offset'] ), absint( $args['number'] ) ), OBJECT );
308
+        if ($subscriptions === false) {
309
+            $subscriptions = $wpdb->get_results($wpdb->prepare("SELECT * FROM  $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint($args['offset']), absint($args['number'])), OBJECT);
310 310
 
311
-            if( ! empty( $subscriptions ) ) {
311
+            if (!empty($subscriptions)) {
312 312
 
313
-                foreach( $subscriptions as $key => $subscription ) {
314
-                    $subscriptions[ $key ] = new WPInv_Subscription( $subscription );
313
+                foreach ($subscriptions as $key => $subscription) {
314
+                    $subscriptions[$key] = new WPInv_Subscription($subscription);
315 315
                 }
316 316
 
317
-                wp_cache_set( $cache_key, $subscriptions, 'subscriptions', 3600 );
317
+                wp_cache_set($cache_key, $subscriptions, 'subscriptions', 3600);
318 318
 
319 319
             }
320 320
 
@@ -329,19 +329,19 @@  discard block
 block discarded – undo
329 329
      * @access  public
330 330
      * @since   1.0.0
331 331
      */
332
-    public function count( $args = array() ) {
332
+    public function count($args = array()) {
333 333
 
334 334
         global $wpdb;
335 335
 
336 336
         $where = ' WHERE 1=1 ';
337 337
 
338 338
         // specific customers
339
-        if( ! empty( $args['id'] ) ) {
339
+        if (!empty($args['id'])) {
340 340
 
341
-            if( is_array( $args['id'] ) ) {
342
-                $ids = implode( ',', array_map('intval', $args['id'] ) );
341
+            if (is_array($args['id'])) {
342
+                $ids = implode(',', array_map('intval', $args['id']));
343 343
             } else {
344
-                $ids = intval( $args['id'] );
344
+                $ids = intval($args['id']);
345 345
             }
346 346
 
347 347
             $where .= " AND `id` IN( {$ids} ) ";
@@ -349,12 +349,12 @@  discard block
 block discarded – undo
349 349
         }
350 350
 
351 351
         // Specific products
352
-        if( ! empty( $args['product_id'] ) ) {
352
+        if (!empty($args['product_id'])) {
353 353
 
354
-            if( is_array( $args['product_id'] ) ) {
355
-                $product_ids = implode( ',', array_map('intval', $args['product_id'] ) );
354
+            if (is_array($args['product_id'])) {
355
+                $product_ids = implode(',', array_map('intval', $args['product_id']));
356 356
             } else {
357
-                $product_ids = intval( $args['product_id'] );
357
+                $product_ids = intval($args['product_id']);
358 358
             }
359 359
 
360 360
             $where .= " AND `product_id` IN( {$product_ids} ) ";
@@ -362,12 +362,12 @@  discard block
 block discarded – undo
362 362
         }
363 363
 
364 364
         // Specific parent payments
365
-        if( ! empty( $args['parent_payment_id'] ) ) {
365
+        if (!empty($args['parent_payment_id'])) {
366 366
 
367
-            if( is_array( $args['parent_payment_id'] ) ) {
368
-                $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) );
367
+            if (is_array($args['parent_payment_id'])) {
368
+                $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id']));
369 369
             } else {
370
-                $parent_payment_ids = intval( $args['parent_payment_id'] );
370
+                $parent_payment_ids = intval($args['parent_payment_id']);
371 371
             }
372 372
 
373 373
             $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) ";
@@ -375,12 +375,12 @@  discard block
 block discarded – undo
375 375
         }
376 376
 
377 377
         // Subscriptoins for specific customers
378
-        if( ! empty( $args['customer_id'] ) ) {
378
+        if (!empty($args['customer_id'])) {
379 379
 
380
-            if( is_array( $args['customer_id'] ) ) {
381
-                $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) );
380
+            if (is_array($args['customer_id'])) {
381
+                $customer_ids = implode(',', array_map('intval', $args['customer_id']));
382 382
             } else {
383
-                $customer_ids = intval( $args['customer_id'] );
383
+                $customer_ids = intval($args['customer_id']);
384 384
             }
385 385
 
386 386
             $where .= " AND `customer_id` IN( {$customer_ids} ) ";
@@ -388,12 +388,12 @@  discard block
 block discarded – undo
388 388
         }
389 389
 
390 390
         // Subscriptions for specific profile IDs
391
-        if( ! empty( $args['profile_id'] ) ) {
391
+        if (!empty($args['profile_id'])) {
392 392
 
393
-            if( is_array( $args['profile_id'] ) ) {
394
-                $profile_ids = implode( ',', array_map('intval', $args['profile_id'] ) );
393
+            if (is_array($args['profile_id'])) {
394
+                $profile_ids = implode(',', array_map('intval', $args['profile_id']));
395 395
             } else {
396
-                $profile_ids = intval( $args['profile_id'] );
396
+                $profile_ids = intval($args['profile_id']);
397 397
             }
398 398
 
399 399
             $where .= " AND `profile_id` IN( {$profile_ids} ) ";
@@ -401,12 +401,12 @@  discard block
 block discarded – undo
401 401
         }
402 402
 
403 403
         // Specific transaction IDs
404
-        if( ! empty( $args['transaction_id'] ) ) {
404
+        if (!empty($args['transaction_id'])) {
405 405
 
406
-            if( is_array( $args['transaction_id'] ) ) {
407
-                $transaction_ids = implode( ',', array_map('sanitize_text_field', $args['transaction_id'] ) );
406
+            if (is_array($args['transaction_id'])) {
407
+                $transaction_ids = implode(',', array_map('sanitize_text_field', $args['transaction_id']));
408 408
             } else {
409
-                $transaction_ids = sanitize_text_field( $args['transaction_id'] );
409
+                $transaction_ids = sanitize_text_field($args['transaction_id']);
410 410
             }
411 411
 
412 412
             $where .= " AND `transaction_id` IN( {$transaction_ids} ) ";
@@ -414,10 +414,10 @@  discard block
 block discarded – undo
414 414
         }
415 415
 
416 416
         // Subscriptions for specific statuses
417
-        if( ! empty( $args['status'] ) ) {
417
+        if (!empty($args['status'])) {
418 418
 
419
-            if( is_array( $args['status'] ) ) {
420
-                $statuses = implode( ',', $args['status'] );
419
+            if (is_array($args['status'])) {
420
+                $statuses = implode(',', $args['status']);
421 421
                 $where  .= " AND `status` IN( {$statuses} ) ";
422 422
             } else {
423 423
                 $statuses = $args['status'];
@@ -429,21 +429,21 @@  discard block
 block discarded – undo
429 429
         }
430 430
 
431 431
         // Subscriptions created for a specific date or in a date range
432
-        if( ! empty( $args['date'] ) ) {
432
+        if (!empty($args['date'])) {
433 433
 
434
-            if( is_array( $args['date'] ) ) {
434
+            if (is_array($args['date'])) {
435 435
 
436
-                if( ! empty( $args['date']['start'] ) ) {
436
+                if (!empty($args['date']['start'])) {
437 437
 
438
-                    $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
438
+                    $start = date('Y-m-d H:i:s', strtotime($args['date']['start']));
439 439
 
440 440
                     $where .= " AND `created` >= '{$start}'";
441 441
 
442 442
                 }
443 443
 
444
-                if( ! empty( $args['date']['end'] ) ) {
444
+                if (!empty($args['date']['end'])) {
445 445
 
446
-                    $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
446
+                    $end = date('Y-m-d H:i:s', strtotime($args['date']['end']));
447 447
 
448 448
                     $where .= " AND `created` <= '{$end}'";
449 449
 
@@ -451,9 +451,9 @@  discard block
 block discarded – undo
451 451
 
452 452
             } else {
453 453
 
454
-                $year  = date( 'Y', strtotime( $args['date'] ) );
455
-                $month = date( 'm', strtotime( $args['date'] ) );
456
-                $day   = date( 'd', strtotime( $args['date'] ) );
454
+                $year  = date('Y', strtotime($args['date']));
455
+                $month = date('m', strtotime($args['date']));
456
+                $day   = date('d', strtotime($args['date']));
457 457
 
458 458
                 $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )";
459 459
             }
@@ -461,21 +461,21 @@  discard block
 block discarded – undo
461 461
         }
462 462
 
463 463
         // Subscriptions with a specific expiration date or in an expiration date range
464
-        if( ! empty( $args['expiration'] ) ) {
464
+        if (!empty($args['expiration'])) {
465 465
 
466
-            if( is_array( $args['expiration'] ) ) {
466
+            if (is_array($args['expiration'])) {
467 467
 
468
-                if( ! empty( $args['expiration']['start'] ) ) {
468
+                if (!empty($args['expiration']['start'])) {
469 469
 
470
-                    $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) );
470
+                    $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start']));
471 471
 
472 472
                     $where .= " AND `expiration` >= '{$start}'";
473 473
 
474 474
                 }
475 475
 
476
-                if( ! empty( $args['expiration']['end'] ) ) {
476
+                if (!empty($args['expiration']['end'])) {
477 477
 
478
-                    $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) );
478
+                    $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end']));
479 479
 
480 480
                     $where .= " AND `expiration` <= '{$end}'";
481 481
 
@@ -483,64 +483,64 @@  discard block
 block discarded – undo
483 483
 
484 484
             } else {
485 485
 
486
-                $year  = date( 'Y', strtotime( $args['expiration'] ) );
487
-                $month = date( 'm', strtotime( $args['expiration'] ) );
488
-                $day   = date( 'd', strtotime( $args['expiration'] ) );
486
+                $year  = date('Y', strtotime($args['expiration']));
487
+                $month = date('m', strtotime($args['expiration']));
488
+                $day   = date('d', strtotime($args['expiration']));
489 489
 
490 490
                 $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )";
491 491
             }
492 492
 
493 493
         }
494 494
 
495
-        if ( ! empty( $args['search'] ) ) {
495
+        if (!empty($args['search'])) {
496 496
 
497
-            if( false !== strpos( 'id:', $args['search'] ) ) {
497
+            if (false !== strpos('id:', $args['search'])) {
498 498
 
499
-                $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) );
500
-                $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'";
499
+                $args['search'] = trim(str_replace('id:', '', $args['search']));
500
+                $where .= " AND `id` = '" . esc_sql($args['search']) . "'";
501 501
 
502
-            } else if( false !== strpos( $args['search'], 'txn:' ) ) {
502
+            } else if (false !== strpos($args['search'], 'txn:')) {
503 503
 
504
-                $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) );
505
-                $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'";
504
+                $args['search'] = trim(str_replace('txn:', '', $args['search']));
505
+                $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'";
506 506
 
507
-            } else if( false !== strpos( $args['search'], 'profile_id:' ) ) {
507
+            } else if (false !== strpos($args['search'], 'profile_id:')) {
508 508
 
509
-                $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) );
510
-                $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'";
509
+                $args['search'] = trim(str_replace('profile_id:', '', $args['search']));
510
+                $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'";
511 511
 
512
-            } else if( false !== strpos( $args['search'], 'product_id:' ) ) {
512
+            } else if (false !== strpos($args['search'], 'product_id:')) {
513 513
 
514
-                $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) );
515
-                $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'";
514
+                $args['search'] = trim(str_replace('product_id:', '', $args['search']));
515
+                $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'";
516 516
 
517
-            } else if( false !== strpos( $args['search'], 'customer_id:' ) ) {
517
+            } else if (false !== strpos($args['search'], 'customer_id:')) {
518 518
 
519
-                $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) );
520
-                $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'";
519
+                $args['search'] = trim(str_replace('customer_id:', '', $args['search']));
520
+                $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'";
521 521
 
522 522
             } else {
523 523
 
524
-                $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )";
524
+                $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )";
525 525
 
526 526
             }
527 527
 
528 528
         }
529 529
 
530
-        $cache_key = md5( 'wpinv_subscriptions_count' . serialize( $args ) );
530
+        $cache_key = md5('wpinv_subscriptions_count' . serialize($args));
531 531
 
532
-        $count = wp_cache_get( $cache_key, 'subscriptions' );
532
+        $count = wp_cache_get($cache_key, 'subscriptions');
533 533
 
534
-        if( $count === false ) {
534
+        if ($count === false) {
535 535
 
536 536
             $sql   = "SELECT COUNT($this->primary_key) FROM " . $this->table_name . "{$where};";
537
-            $count = $wpdb->get_var( $sql );
537
+            $count = $wpdb->get_var($sql);
538 538
 
539
-            wp_cache_set( $cache_key, $count, 'subscriptions', 3600 );
539
+            wp_cache_set($cache_key, $count, 'subscriptions', 3600);
540 540
 
541 541
         }
542 542
 
543
-        return absint( $count );
543
+        return absint($count);
544 544
 
545 545
     }
546 546
 
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
     public function create_table() {
554 554
         global $wpdb;
555 555
 
556
-        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
556
+        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
557 557
 
558 558
         $sql = "CREATE TABLE " . $this->table_name . " (
559 559
         id bigint(20) NOT NULL AUTO_INCREMENT,
@@ -578,9 +578,9 @@  discard block
 block discarded – undo
578 578
         KEY customer_and_status ( customer_id, status)
579 579
         ) CHARACTER SET utf8 COLLATE utf8_general_ci;";
580 580
 
581
-        dbDelta( $sql );
581
+        dbDelta($sql);
582 582
 
583
-        update_option( $this->table_name . '_db_version', $this->version );
583
+        update_option($this->table_name . '_db_version', $this->version);
584 584
     }
585 585
 
586 586
 }
587 587
\ No newline at end of file
Please login to merge, or discard this patch.