Passed
Pull Request — master (#126)
by Kiran
03:46
created
includes/gateways/manual.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_manual_cc_form', '__return_false' );
6 8
 
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 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_manual_cc_form', '__return_false' );
5
+add_action('wpinv_manual_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_manual_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_manual_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
     /*
@@ -41,22 +41,22 @@  discard block
 block discarded – undo
41 41
     );
42 42
 
43 43
     // Record the pending payment
44
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
44
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
45 45
     
46
-    if ( !empty( $invoice ) ) {        
47
-        wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() );
48
-        wpinv_update_payment_status( $invoice, 'publish' );
46
+    if (!empty($invoice)) {        
47
+        wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key());
48
+        wpinv_update_payment_status($invoice, 'publish');
49 49
         
50 50
         // Empty the shopping cart
51 51
         wpinv_empty_cart();
52 52
         
53
-        do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data );
53
+        do_action('wpinv_send_to_success_page', $invoice->ID, $payment_data);
54 54
         
55
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
55
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
56 56
     } else {
57
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
57
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
58 58
         // If errors are present, send the user back to the purchase page so they can be corrected
59
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
59
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
60 60
     }
61 61
 }
62
-add_action( 'wpinv_gateway_manual', 'wpinv_process_manual_payment' );
63 62
\ No newline at end of file
63
+add_action('wpinv_gateway_manual', 'wpinv_process_manual_payment');
64 64
\ No newline at end of file
Please login to merge, or discard this patch.
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   +33 added lines, -33 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,26 +64,26 @@  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 );
90 89
\ No newline at end of file
90
+add_action('wpinv_send_to_success_page', 'wpinv_bank_transfer_send_notification', 10, 2);
91 91
\ 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
@@ -218,262 +218,262 @@  discard block
 block discarded – undo
218 218
 add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 );
219 219
 
220 220
 function wpinv_process_paypal_ipn() {
221
-	// Check the request method is POST
222
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
223
-		return;
224
-	}
225
-
226
-	// Set initial post data to empty string
227
-	$post_data = '';
228
-
229
-	// Fallback just in case post_max_size is lower than needed
230
-	if ( ini_get( 'allow_url_fopen' ) ) {
231
-		$post_data = file_get_contents( 'php://input' );
232
-	} else {
233
-		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
234
-		ini_set( 'post_max_size', '12M' );
235
-	}
236
-	// Start the encoded data collection with notification command
237
-	$encoded_data = 'cmd=_notify-validate';
238
-
239
-	// Get current arg separator
240
-	$arg_separator = wpinv_get_php_arg_separator_output();
241
-
242
-	// Verify there is a post_data
243
-	if ( $post_data || strlen( $post_data ) > 0 ) {
244
-		// Append the data
245
-		$encoded_data .= $arg_separator.$post_data;
246
-	} else {
247
-		// Check if POST is empty
248
-		if ( empty( $_POST ) ) {
249
-			// Nothing to do
250
-			return;
251
-		} else {
252
-			// Loop through each POST
253
-			foreach ( $_POST as $key => $value ) {
254
-				// Encode the value and append the data
255
-				$encoded_data .= $arg_separator."$key=" . urlencode( $value );
256
-			}
257
-		}
258
-	}
259
-
260
-	// Convert collected post data to an array
261
-	parse_str( $encoded_data, $encoded_data_array );
262
-
263
-	foreach ( $encoded_data_array as $key => $value ) {
264
-		if ( false !== strpos( $key, 'amp;' ) ) {
265
-			$new_key = str_replace( '&amp;', '&', $key );
266
-			$new_key = str_replace( 'amp;', '&' , $new_key );
267
-
268
-			unset( $encoded_data_array[ $key ] );
269
-			$encoded_data_array[ $new_key ] = $value;
270
-		}
271
-	}
272
-
273
-	// Get the PayPal redirect uri
274
-	$paypal_redirect = wpinv_get_paypal_redirect( true );
275
-
276
-	if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
277
-		// Validate the IPN
278
-
279
-		$remote_post_vars      = array(
280
-			'method'           => 'POST',
281
-			'timeout'          => 45,
282
-			'redirection'      => 5,
283
-			'httpversion'      => '1.1',
284
-			'blocking'         => true,
285
-			'headers'          => array(
286
-				'host'         => 'www.paypal.com',
287
-				'connection'   => 'close',
288
-				'content-type' => 'application/x-www-form-urlencoded',
289
-				'post'         => '/cgi-bin/webscr HTTP/1.1',
290
-
291
-			),
292
-			'sslverify'        => false,
293
-			'body'             => $encoded_data_array
294
-		);
295
-
296
-		// Get response
297
-		$api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
298
-
299
-		if ( is_wp_error( $api_response ) ) {
300
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
301
-			return; // Something went wrong
302
-		}
303
-
304
-		if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
305
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
306
-			return; // Response not okay
307
-		}
308
-	}
309
-
310
-	// Check if $post_data_array has been populated
311
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
312
-		return;
313
-
314
-	$defaults = array(
315
-		'txn_type'       => '',
316
-		'payment_status' => ''
317
-	);
318
-
319
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
320
-
321
-	$invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
221
+    // Check the request method is POST
222
+    if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
223
+        return;
224
+    }
225
+
226
+    // Set initial post data to empty string
227
+    $post_data = '';
228
+
229
+    // Fallback just in case post_max_size is lower than needed
230
+    if ( ini_get( 'allow_url_fopen' ) ) {
231
+        $post_data = file_get_contents( 'php://input' );
232
+    } else {
233
+        // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
234
+        ini_set( 'post_max_size', '12M' );
235
+    }
236
+    // Start the encoded data collection with notification command
237
+    $encoded_data = 'cmd=_notify-validate';
238
+
239
+    // Get current arg separator
240
+    $arg_separator = wpinv_get_php_arg_separator_output();
241
+
242
+    // Verify there is a post_data
243
+    if ( $post_data || strlen( $post_data ) > 0 ) {
244
+        // Append the data
245
+        $encoded_data .= $arg_separator.$post_data;
246
+    } else {
247
+        // Check if POST is empty
248
+        if ( empty( $_POST ) ) {
249
+            // Nothing to do
250
+            return;
251
+        } else {
252
+            // Loop through each POST
253
+            foreach ( $_POST as $key => $value ) {
254
+                // Encode the value and append the data
255
+                $encoded_data .= $arg_separator."$key=" . urlencode( $value );
256
+            }
257
+        }
258
+    }
259
+
260
+    // Convert collected post data to an array
261
+    parse_str( $encoded_data, $encoded_data_array );
262
+
263
+    foreach ( $encoded_data_array as $key => $value ) {
264
+        if ( false !== strpos( $key, 'amp;' ) ) {
265
+            $new_key = str_replace( '&amp;', '&', $key );
266
+            $new_key = str_replace( 'amp;', '&' , $new_key );
267
+
268
+            unset( $encoded_data_array[ $key ] );
269
+            $encoded_data_array[ $new_key ] = $value;
270
+        }
271
+    }
272
+
273
+    // Get the PayPal redirect uri
274
+    $paypal_redirect = wpinv_get_paypal_redirect( true );
275
+
276
+    if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
277
+        // Validate the IPN
278
+
279
+        $remote_post_vars      = array(
280
+            'method'           => 'POST',
281
+            'timeout'          => 45,
282
+            'redirection'      => 5,
283
+            'httpversion'      => '1.1',
284
+            'blocking'         => true,
285
+            'headers'          => array(
286
+                'host'         => 'www.paypal.com',
287
+                'connection'   => 'close',
288
+                'content-type' => 'application/x-www-form-urlencoded',
289
+                'post'         => '/cgi-bin/webscr HTTP/1.1',
290
+
291
+            ),
292
+            'sslverify'        => false,
293
+            'body'             => $encoded_data_array
294
+        );
295
+
296
+        // Get response
297
+        $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
298
+
299
+        if ( is_wp_error( $api_response ) ) {
300
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
301
+            return; // Something went wrong
302
+        }
303
+
304
+        if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
305
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
306
+            return; // Response not okay
307
+        }
308
+    }
309
+
310
+    // Check if $post_data_array has been populated
311
+    if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
312
+        return;
313
+
314
+    $defaults = array(
315
+        'txn_type'       => '',
316
+        'payment_status' => ''
317
+    );
318
+
319
+    $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
320
+
321
+    $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
322 322
     
323
-	wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
324
-	wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ );
325
-
326
-	if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
327
-		// Allow PayPal IPN types to be processed separately
328
-		do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
329
-	} else {
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 );
332
-	}
333
-	exit;
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
+
326
+    if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
327
+        // Allow PayPal IPN types to be processed separately
328
+        do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
329
+    } else {
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 );
332
+    }
333
+    exit;
334 334
 }
335 335
 add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' );
336 336
 
337 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
-		return;
340
-	}
341
-
342
-	if( empty( $invoice_id ) ) {
343
-		return;
344
-	}
345
-
346
-	// Collect payment details
347
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
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 );
353
-
354
-	if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
355
-		return; // this isn't a PayPal standard IPN
356
-	}
357
-
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 );
363
-		return;
364
-	}
365
-
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 );
371
-		return;
372
-	}
373
-
374
-	if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
375
-		// This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
376
-		// No email associated with purchase, so store from PayPal
377
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
378
-
379
-		// Setup and store the customer's details
380
-		$user_info = array(
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'] ),
385
-			'discount'   => '',
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;
392
-
393
-		$payment_meta['user_info'] = $user_info;
394
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
395
-	}
396
-
397
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
398
-		// Process a refund
399
-		wpinv_process_paypal_refund( $data, $invoice_id );
400
-	} else {
401
-		if ( get_post_status( $invoice_id ) == 'publish' ) {
402
-			return; // Only paid payments once
403
-		}
404
-
405
-		// Retrieve the total purchase amount (before PayPal)
406
-		$payment_amount = wpinv_payment_total( $invoice_id );
407
-
408
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
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 );
413
-			return;
414
-		}
415
-		if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
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 );
420
-			return;
421
-		}
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'] ) ) {
428
-			// Look for possible pending reasons, such as an echeck
429
-			$note = '';
430
-
431
-			switch( strtolower( $data['pending_reason'] ) ) {
432
-				case 'echeck' :
433
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
434
-					break;
338
+    if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
339
+        return;
340
+    }
341
+
342
+    if( empty( $invoice_id ) ) {
343
+        return;
344
+    }
345
+
346
+    // Collect payment details
347
+    $purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
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 );
353
+
354
+    if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
355
+        return; // this isn't a PayPal standard IPN
356
+    }
357
+
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 );
363
+        return;
364
+    }
365
+
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 );
371
+        return;
372
+    }
373
+
374
+    if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
375
+        // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
376
+        // No email associated with purchase, so store from PayPal
377
+        wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
378
+
379
+        // Setup and store the customer's details
380
+        $user_info = array(
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'] ),
385
+            'discount'   => '',
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;
392
+
393
+        $payment_meta['user_info'] = $user_info;
394
+        wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
395
+    }
396
+
397
+    if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
398
+        // Process a refund
399
+        wpinv_process_paypal_refund( $data, $invoice_id );
400
+    } else {
401
+        if ( get_post_status( $invoice_id ) == 'publish' ) {
402
+            return; // Only paid payments once
403
+        }
404
+
405
+        // Retrieve the total purchase amount (before PayPal)
406
+        $payment_amount = wpinv_payment_total( $invoice_id );
407
+
408
+        if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
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 );
413
+            return;
414
+        }
415
+        if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
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 );
420
+            return;
421
+        }
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'] ) ) {
428
+            // Look for possible pending reasons, such as an echeck
429
+            $note = '';
430
+
431
+            switch( strtolower( $data['pending_reason'] ) ) {
432
+                case 'echeck' :
433
+                    $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
434
+                    break;
435 435
 				
436 436
                 case 'address' :
437
-					$note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
438
-					break;
437
+                    $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
438
+                    break;
439 439
 				
440 440
                 case 'intl' :
441
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
442
-					break;
441
+                    $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
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' );
446
-					break;
445
+                    $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
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' );
451
-					break;
450
+                    $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
451
+                    break;
452 452
 				
453 453
                 case 'unilateral' :
454
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
455
-					break;
454
+                    $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
455
+                    break;
456 456
 				
457 457
                 case 'upgrade' :
458
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
459
-					break;
458
+                    $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
459
+                    break;
460 460
 				
461 461
                 case 'verify' :
462
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
463
-					break;
464
-
465
-				case 'other' :
466
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
467
-					break;
468
-			}
469
-
470
-			if ( ! empty( $note ) ) {
471
-				wpinv_insert_payment_note( $invoice_id, $note, '', '', true );
472
-			}
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 );
475
-		}
476
-	}
462
+                    $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
463
+                    break;
464
+
465
+                case 'other' :
466
+                    $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
467
+                    break;
468
+            }
469
+
470
+            if ( ! empty( $note ) ) {
471
+                wpinv_insert_payment_note( $invoice_id, $note, '', '', true );
472
+            }
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 );
475
+        }
476
+    }
477 477
 }
478 478
 add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 );
479 479
 
@@ -661,34 +661,34 @@  discard block
 block discarded – undo
661 661
 }
662 662
 
663 663
 function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
664
-	// Collect payment details
664
+    // Collect payment details
665 665
 
666
-	if( empty( $invoice_id ) ) {
667
-		return;
668
-	}
666
+    if( empty( $invoice_id ) ) {
667
+        return;
668
+    }
669 669
 
670
-	if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
671
-		return; // Only refund payments once
672
-	}
670
+    if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
671
+        return; // Only refund payments once
672
+    }
673 673
 
674
-	$payment_amount = wpinv_payment_total( $invoice_id );
675
-	$refund_amount  = $data['mc_gross'] * -1;
674
+    $payment_amount = wpinv_payment_total( $invoice_id );
675
+    $refund_amount  = $data['mc_gross'] * -1;
676 676
 
677
-	do_action( 'wpinv_paypal_refund_request', $data, $invoice_id );
677
+    do_action( 'wpinv_paypal_refund_request', $data, $invoice_id );
678 678
 
679
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
680
-		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 );
679
+    if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
680
+        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 );
681 681
 
682
-		do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount );
682
+        do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount );
683 683
 
684
-		return; // This is a partial refund
685
-	}
684
+        return; // This is a partial refund
685
+    }
686 686
 
687
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
688
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true );
689
-	wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
687
+    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
688
+    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true );
689
+    wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
690 690
 
691
-	do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id );
691
+    do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id );
692 692
 }
693 693
 
694 694
 function wpinv_get_paypal_redirect( $ssl_check = false ) {
Please login to merge, or discard this patch.
Spacing   +262 added lines, -262 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  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
-function wpinv_process_paypal_payment( $purchase_data ) {
9
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
10
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
8
+function wpinv_process_paypal_payment($purchase_data) {
9
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
10
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
11 11
     }
12 12
 
13 13
     // Collect payment data
@@ -25,30 +25,30 @@  discard block
 block discarded – undo
25 25
     );
26 26
 
27 27
     // Record the pending payment
28
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
28
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
29 29
 
30 30
     // Check payment
31
-    if ( ! $invoice ) {
31
+    if (!$invoice) {
32 32
         // Record the error
33
-        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 );
33
+        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);
34 34
         // Problems? send back
35
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
35
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
36 36
     } else {
37 37
         // Only send to PayPal if the pending payment is created successfully
38
-        $listener_url = wpinv_get_ipn_url( 'paypal' );
38
+        $listener_url = wpinv_get_ipn_url('paypal');
39 39
 
40 40
         // Get the success url
41
-        $return_url = add_query_arg( array(
41
+        $return_url = add_query_arg(array(
42 42
                 'payment-confirm' => 'paypal',
43 43
                 'invoice-id' => $invoice->ID
44
-            ), get_permalink( wpinv_get_option( 'success_page', false ) ) );
44
+            ), get_permalink(wpinv_get_option('success_page', false)));
45 45
 
46 46
         // Get the PayPal redirect uri
47
-        $paypal_redirect = trailingslashit( wpinv_get_paypal_redirect() ) . '?';
47
+        $paypal_redirect = trailingslashit(wpinv_get_paypal_redirect()) . '?';
48 48
 
49 49
         // Setup PayPal arguments
50 50
         $paypal_args = array(
51
-            'business'      => wpinv_get_option( 'paypal_email', false ),
51
+            'business'      => wpinv_get_option('paypal_email', false),
52 52
             'email'         => $invoice->get_email(),
53 53
             'first_name'    => $invoice->get_first_name(),
54 54
             'last_name'     => $invoice->get_last_name(),
@@ -57,16 +57,16 @@  discard block
 block discarded – undo
57 57
             'shipping'      => '0',
58 58
             'no_note'       => '1',
59 59
             'currency_code' => wpinv_get_currency(),
60
-            'charset'       => get_bloginfo( 'charset' ),
60
+            'charset'       => get_bloginfo('charset'),
61 61
             'custom'        => $invoice->ID,
62 62
             'rm'            => '2',
63 63
             'return'        => $return_url,
64
-            'cancel_return' => wpinv_get_failed_transaction_uri( '?invoice-id=' . $invoice->ID ),
64
+            'cancel_return' => wpinv_get_failed_transaction_uri('?invoice-id=' . $invoice->ID),
65 65
             'notify_url'    => $listener_url,
66
-            'cbt'           => get_bloginfo( 'name' ),
66
+            'cbt'           => get_bloginfo('name'),
67 67
             'bn'            => 'WPInvoicing_SP',
68 68
             'lc'            => 'US', // this will force paypal site to english
69
-            'landing_page'  => apply_filters( 'wpinv_paypal_standard_landing_page', 'billing', $invoice ), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account.
69
+            'landing_page'  => apply_filters('wpinv_paypal_standard_landing_page', 'billing', $invoice), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account.
70 70
         );
71 71
 
72 72
         $paypal_args['address1'] = $invoice->get_address();
@@ -80,57 +80,57 @@  discard block
 block discarded – undo
80 80
             'upload' => '1'
81 81
         );
82 82
 
83
-        $paypal_args = array_merge( $paypal_extra_args, $paypal_args );
83
+        $paypal_args = array_merge($paypal_extra_args, $paypal_args);
84 84
 
85 85
         // Add cart items
86 86
         $i = 1;
87
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
88
-            foreach ( $purchase_data['cart_details'] as $item ) {
87
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
88
+            foreach ($purchase_data['cart_details'] as $item) {
89 89
                 $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1;
90
-                $item_amount = wpinv_sanitize_amount( $item['subtotal'] / $item['quantity'], 2 );
90
+                $item_amount = wpinv_sanitize_amount($item['subtotal'] / $item['quantity'], 2);
91 91
 
92
-                if ( $item_amount <= 0 ) {
92
+                if ($item_amount <= 0) {
93 93
                     $item_amount = 0;
94 94
                 }
95 95
 
96
-                $paypal_args['item_number_' . $i ]      = $item['id'];
97
-                $paypal_args['item_name_' . $i ]        = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) );
98
-                $paypal_args['quantity_' . $i ]         = $item['quantity'];
99
-                $paypal_args['amount_' . $i ]           = $item_amount;
100
-                $paypal_args['discount_amount_' . $i ]  = wpinv_sanitize_amount( $item['discount'], 2 );
96
+                $paypal_args['item_number_' . $i]      = $item['id'];
97
+                $paypal_args['item_name_' . $i]        = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8'));
98
+                $paypal_args['quantity_' . $i]         = $item['quantity'];
99
+                $paypal_args['amount_' . $i]           = $item_amount;
100
+                $paypal_args['discount_amount_' . $i]  = wpinv_sanitize_amount($item['discount'], 2);
101 101
 
102 102
                 $i++;
103 103
             }
104 104
         }
105 105
 
106 106
         // Add taxes to the cart
107
-        if ( wpinv_use_taxes() ) {
108
-            $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax(), 2 );
107
+        if (wpinv_use_taxes()) {
108
+            $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax(), 2);
109 109
         }
110 110
 
111
-        $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice );
111
+        $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice);
112 112
 
113 113
         // Build query
114
-        $paypal_redirect .= http_build_query( $paypal_args );
114
+        $paypal_redirect .= http_build_query($paypal_args);
115 115
 
116 116
         // Fix for some sites that encode the entities
117
-        $paypal_redirect = str_replace( '&amp;', '&', $paypal_redirect );
117
+        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
118 118
 
119 119
         // Get rid of cart contents
120 120
         wpinv_empty_cart();
121 121
         
122 122
         // Redirect to PayPal
123
-        wp_redirect( $paypal_redirect );
123
+        wp_redirect($paypal_redirect);
124 124
         exit;
125 125
     }
126 126
 }
127
-add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' );
127
+add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment');
128 128
 
129
-function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) {
130
-    if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) {
131
-        $item   = new WPInv_Item( $item_id );
129
+function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) {
130
+    if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) {
131
+        $item = new WPInv_Item($item_id);
132 132
         
133
-        if ( empty( $item ) ) {
133
+        if (empty($item)) {
134 134
             return $paypal_args;
135 135
         }
136 136
 
@@ -138,24 +138,24 @@  discard block
 block discarded – undo
138 138
         $interval           = $item->get_recurring_interval();
139 139
         $bill_times         = (int)$item->get_recurring_limit();
140 140
         
141
-        $initial_amount     = wpinv_sanitize_amount( $invoice->get_total(), 2 );
142
-        $recurring_amount   = wpinv_sanitize_amount( $invoice->get_recurring_details( 'total' ), 2 );
141
+        $initial_amount     = wpinv_sanitize_amount($invoice->get_total(), 2);
142
+        $recurring_amount   = wpinv_sanitize_amount($invoice->get_recurring_details('total'), 2);
143 143
         
144 144
         $paypal_args['cmd'] = '_xclick-subscriptions';
145 145
         $paypal_args['sra'] = '1';
146 146
         $paypal_args['src'] = '1';
147 147
         
148 148
         // Set item description
149
-        $paypal_args['item_name']   = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( array( 'id' => $item->ID ) ), ENT_COMPAT, 'UTF-8' ) );
149
+        $paypal_args['item_name'] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name(array('id' => $item->ID)), ENT_COMPAT, 'UTF-8'));
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
-	parse_str( $encoded_data, $encoded_data_array );
261
+	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,259 +316,259 @@  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 528
     // Retrieve pending subscription from database and update it's status to active and set proper profile ID
529
-    $subscription->update( array( 'profile_id' => $ipn_data['subscr_id'], 'status' => $status ) );
529
+    $subscription->update(array('profile_id' => $ipn_data['subscr_id'], 'status' => $status));
530 530
 }
531 531
 
532 532
 /**
533 533
  * Process the subscription payment received IPN.
534 534
  */
535
-function wpinv_process_paypal_subscr_payment( $ipn_data ) {
536
-    $parent_invoice_id = absint( $ipn_data['custom'] );
535
+function wpinv_process_paypal_subscr_payment($ipn_data) {
536
+    $parent_invoice_id = absint($ipn_data['custom']);
537 537
 
538
-    $parent_invoice = wpinv_get_invoice( $parent_invoice_id );
539
-    if ( empty( $parent_invoice ) ) {
538
+    $parent_invoice = wpinv_get_invoice($parent_invoice_id);
539
+    if (empty($parent_invoice)) {
540 540
         return;
541 541
     }
542 542
 
543
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
544
-    if ( false === $subscription ) {
543
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
544
+    if (false === $subscription) {
545 545
         return;
546 546
     }
547 547
 
548
-    $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id );
548
+    $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id);
549 549
     $times_billed   = $subscription->get_times_billed();
550 550
 
551 551
     // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet.
552
-    if ( empty( $times_billed ) && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) {
553
-        wpinv_update_payment_status( $parent_invoice_id, 'publish' );
552
+    if (empty($times_billed) && (!$transaction_id || $transaction_id == $parent_invoice_id)) {
553
+        wpinv_update_payment_status($parent_invoice_id, 'publish');
554 554
         sleep(1);
555 555
         
556 556
         // This is the very first payment
557
-        wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] );
558
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true );
557
+        wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']);
558
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true);
559 559
         return;
560 560
     }
561 561
     
562
-    if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) {
562
+    if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) {
563 563
         return; // Payment already recorded
564 564
     }
565 565
 
566
-    $currency_code = strtolower( $ipn_data['mc_currency'] );
566
+    $currency_code = strtolower($ipn_data['mc_currency']);
567 567
 
568 568
     // verify details
569
-    if ( $currency_code != strtolower( wpinv_get_currency() ) ) {
569
+    if ($currency_code != strtolower(wpinv_get_currency())) {
570 570
         // the currency code is invalid
571
-        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) );
571
+        wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data)));
572 572
         return;
573 573
     }
574 574
 
@@ -578,11 +578,11 @@  discard block
 block discarded – undo
578 578
         'gateway'        => 'paypal'
579 579
     );
580 580
     
581
-    $invoice_id = $subscription->add_payment( $args );
581
+    $invoice_id = $subscription->add_payment($args);
582 582
 
583
-    if ( $invoice_id > 0 ) {
584
-        wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true );
585
-        wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true );
583
+    if ($invoice_id > 0) {
584
+        wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true);
585
+        wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true);
586 586
 
587 587
         $subscription->renew();
588 588
     }
@@ -591,10 +591,10 @@  discard block
 block discarded – undo
591 591
 /**
592 592
  * Process the subscription canceled IPN.
593 593
  */
594
-function wpinv_process_paypal_subscr_cancel( $ipn_data ) {
595
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
594
+function wpinv_process_paypal_subscr_cancel($ipn_data) {
595
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
596 596
 
597
-    if( false === $subscription ) {
597
+    if (false === $subscription) {
598 598
         return;
599 599
     }
600 600
 
@@ -604,10 +604,10 @@  discard block
 block discarded – undo
604 604
 /**
605 605
  * Process the subscription expired IPN.
606 606
  */
607
-function wpinv_process_paypal_subscr_eot( $ipn_data ) {
608
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
607
+function wpinv_process_paypal_subscr_eot($ipn_data) {
608
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
609 609
 
610
-    if( false === $subscription ) {
610
+    if (false === $subscription) {
611 611
         return;
612 612
     }
613 613
 
@@ -617,40 +617,40 @@  discard block
 block discarded – undo
617 617
 /**
618 618
  * Process the subscription payment failed IPN.
619 619
  */
620
-function wpinv_process_paypal_subscr_failed( $ipn_data ) {
621
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
620
+function wpinv_process_paypal_subscr_failed($ipn_data) {
621
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
622 622
 
623
-    if( false === $subscription ) {
623
+    if (false === $subscription) {
624 624
         return;
625 625
     }
626 626
 
627 627
     $subscription->failing();
628 628
 
629
-    do_action( 'wpinv_recurring_payment_failed', $subscription );
629
+    do_action('wpinv_recurring_payment_failed', $subscription);
630 630
 }
631 631
 
632 632
 /**
633 633
  * Retrieve the subscription this IPN notice is for.
634 634
  */
635
-function wpinv_get_paypal_subscription( $ipn_data = array() ) {
636
-    $parent_invoice_id = absint( $ipn_data['custom'] );
635
+function wpinv_get_paypal_subscription($ipn_data = array()) {
636
+    $parent_invoice_id = absint($ipn_data['custom']);
637 637
 
638
-    if( empty( $parent_invoice_id ) ) {
638
+    if (empty($parent_invoice_id)) {
639 639
         return false;
640 640
     }
641 641
 
642
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
643
-    if ( empty( $invoice ) ) {
642
+    $invoice = wpinv_get_invoice($parent_invoice_id);
643
+    if (empty($invoice)) {
644 644
         return false;
645 645
     }
646 646
 
647
-    $subscription = new WPInv_Subscription( $ipn_data['subscr_id'], true );
647
+    $subscription = new WPInv_Subscription($ipn_data['subscr_id'], true);
648 648
 
649
-    if ( ! ( ! empty( $subscription ) && $subscription->id > 0 ) ) {
650
-        $subscription = wpinv_get_subscription( $parent_invoice_id );
649
+    if (!(!empty($subscription) && $subscription->id > 0)) {
650
+        $subscription = wpinv_get_subscription($parent_invoice_id);
651 651
 
652
-        if ( ! empty( $subscription ) && $subscription->id > 0 ) {
653
-            $subscription->update( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) );
652
+        if (!empty($subscription) && $subscription->id > 0) {
653
+            $subscription->update(array('profile_id' => sanitize_text_field($ipn_data['subscr_id'])));
654 654
         } else {
655 655
             return false;
656 656
         }
@@ -660,46 +660,46 @@  discard block
 block discarded – undo
660 660
 
661 661
 }
662 662
 
663
-function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
663
+function wpinv_process_paypal_refund($data, $invoice_id = 0) {
664 664
 	// Collect payment details
665 665
 
666
-	if( empty( $invoice_id ) ) {
666
+	if (empty($invoice_id)) {
667 667
 		return;
668 668
 	}
669 669
 
670
-	if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
670
+	if (get_post_status($invoice_id) == 'wpi-refunded') {
671 671
 		return; // Only refund payments once
672 672
 	}
673 673
 
674
-	$payment_amount = wpinv_payment_total( $invoice_id );
674
+	$payment_amount = wpinv_payment_total($invoice_id);
675 675
 	$refund_amount  = $data['mc_gross'] * -1;
676 676
 
677
-	do_action( 'wpinv_paypal_refund_request', $data, $invoice_id );
677
+	do_action('wpinv_paypal_refund_request', $data, $invoice_id);
678 678
 
679
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
680
-		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 );
679
+	if (number_format((float)$refund_amount, 2) < number_format((float)$payment_amount, 2)) {
680
+		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);
681 681
 
682
-		do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount );
682
+		do_action('wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount);
683 683
 
684 684
 		return; // This is a partial refund
685 685
 	}
686 686
 
687
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
688
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true );
689
-	wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
687
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code']), '', '', true);
688
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true);
689
+	wpinv_update_payment_status($invoice_id, 'wpi-refunded');
690 690
 
691
-	do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id );
691
+	do_action('wpinv_paypal_invoice_fully_refunded', $data, $invoice_id);
692 692
 }
693 693
 
694
-function wpinv_get_paypal_redirect( $ssl_check = false ) {
695
-    if ( is_ssl() || ! $ssl_check ) {
694
+function wpinv_get_paypal_redirect($ssl_check = false) {
695
+    if (is_ssl() || !$ssl_check) {
696 696
         $protocol = 'https://';
697 697
     } else {
698 698
         $protocol = 'http://';
699 699
     }
700 700
 
701 701
     // Check the current payment mode
702
-    if ( wpinv_is_test_mode( 'paypal' ) ) {
702
+    if (wpinv_is_test_mode('paypal')) {
703 703
         // Test mode
704 704
         $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr';
705 705
     } else {
@@ -707,79 +707,79 @@  discard block
 block discarded – undo
707 707
         $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr';
708 708
     }
709 709
 
710
-    return apply_filters( 'wpinv_paypal_uri', $paypal_uri );
710
+    return apply_filters('wpinv_paypal_uri', $paypal_uri);
711 711
 }
712 712
 
713
-function wpinv_paypal_success_page_content( $content ) {
713
+function wpinv_paypal_success_page_content($content) {
714 714
     global $wpi_invoice;
715 715
     
716 716
     $session = wpinv_get_checkout_session();
717 717
 
718
-    if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] )  ) {
718
+    if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) {
719 719
         return $content;
720 720
     }
721 721
 
722
-    $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] );
722
+    $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']);
723 723
 
724
-    if ( empty(  $invoice_id ) ) {
724
+    if (empty($invoice_id)) {
725 725
         return $content;
726 726
     }
727 727
 
728
-    $wpi_invoice = wpinv_get_invoice( $invoice_id );
728
+    $wpi_invoice = wpinv_get_invoice($invoice_id);
729 729
     
730
-    if ( !empty( $wpi_invoice ) && 'wpi-pending' == $wpi_invoice->status ) {
730
+    if (!empty($wpi_invoice) && 'wpi-pending' == $wpi_invoice->status) {
731 731
         // Payment is still pending so show processing indicator to fix the Race Condition, issue #
732 732
         ob_start();
733
-        wpinv_get_template_part( 'wpinv-payment-processing' );
733
+        wpinv_get_template_part('wpinv-payment-processing');
734 734
         $content = ob_get_clean();
735 735
     }
736 736
 
737 737
     return $content;
738 738
 }
739
-add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' );
739
+add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content');
740 740
 
741
-function wpinv_paypal_get_transaction_id( $invoice_id ) {
741
+function wpinv_paypal_get_transaction_id($invoice_id) {
742 742
     $transaction_id = '';
743
-    $notes = wpinv_get_invoice_notes( $invoice_id );
743
+    $notes = wpinv_get_invoice_notes($invoice_id);
744 744
 
745
-    foreach ( $notes as $note ) {
746
-        if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) {
745
+    foreach ($notes as $note) {
746
+        if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) {
747 747
             $transaction_id = $match[1];
748 748
             continue;
749 749
         }
750 750
     }
751 751
 
752
-    return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id );
752
+    return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id);
753 753
 }
754
-add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 );
754
+add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1);
755 755
 
756
-function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
757
-    if ( $invoice->is_free_trial() || $transaction_id == $invoice_id ) { // Free trial does not have transaction at PayPal.
756
+function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) {
757
+    if ($invoice->is_free_trial() || $transaction_id == $invoice_id) { // Free trial does not have transaction at PayPal.
758 758
         $transaction_url = $invoice->get_view_url();
759 759
     } else {
760
-        $sandbox = wpinv_is_test_mode( 'paypal' ) ? '.sandbox' : '';
760
+        $sandbox = wpinv_is_test_mode('paypal') ? '.sandbox' : '';
761 761
         $transaction_url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=' . $transaction_id;
762 762
     }
763 763
 
764
-    $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>';
764
+    $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>';
765 765
 
766
-    return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice );
766
+    return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice);
767 767
 }
768
-add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 );
768
+add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3);
769 769
 
770 770
 function wpinv_is_paypal_valid_for_use() {
771
-    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' ) ) );
771
+    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')));
772 772
 }
773 773
 
774
-function wpinv_check_paypal_currency_support( $gateway_list ) {
775
-    if ( isset( $gateway_list['paypal'] ) && ! wpinv_is_paypal_valid_for_use() ) {
776
-        unset( $gateway_list['paypal'] );
774
+function wpinv_check_paypal_currency_support($gateway_list) {
775
+    if (isset($gateway_list['paypal']) && !wpinv_is_paypal_valid_for_use()) {
776
+        unset($gateway_list['paypal']);
777 777
     }
778 778
     return $gateway_list;
779 779
 }
780
-add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1 );
780
+add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1);
781 781
 
782
-function wpinv_gateway_paypal_button_label( $label ) {
783
-    return __( 'Proceed to PayPal', 'invoicing' );
782
+function wpinv_gateway_paypal_button_label($label) {
783
+    return __('Proceed to PayPal', 'invoicing');
784 784
 }
785
-add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 );
786 785
\ No newline at end of file
786
+add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1);
787 787
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-address-functions.php 3 patches
Indentation   +278 added lines, -278 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
 function wpinv_is_base_country( $country ) {
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
 }
41 41
 
42 42
 function wpinv_get_default_state() {
43
-	$state = wpinv_get_option( 'default_state', false );
43
+    $state = wpinv_get_option( 'default_state', false );
44 44
 
45
-	return apply_filters( 'wpinv_default_state', $state );
45
+    return apply_filters( 'wpinv_default_state', $state );
46 46
 }
47 47
 
48 48
 function wpinv_state_name( $state_code = '', $country_code = '' ) {
@@ -115,260 +115,260 @@  discard block
 block discarded – undo
115 115
 }
116 116
 
117 117
 function wpinv_get_country_list( $first_empty = false ) {
118
-	$countries = array(
119
-		'US' => __('United States', 'invoicing'),
120
-		'CA' => __('Canada', 'invoicing'),
121
-		'GB' => __('United Kingdom', 'invoicing'),
122
-		'AF' => __('Afghanistan', 'invoicing'),
123
-		'AX' => __('Aland Islands', 'invoicing'),
124
-		'AL' => __('Albania', 'invoicing'),
125
-		'DZ' => __('Algeria', 'invoicing'),
126
-		'AS' => __('American Samoa', 'invoicing'),
127
-		'AD' => __('Andorra', 'invoicing'),
128
-		'AO' => __('Angola', 'invoicing'),
129
-		'AI' => __('Anguilla', 'invoicing'),
130
-		'AQ' => __('Antarctica', 'invoicing'),
131
-		'AG' => __('Antigua and Barbuda', 'invoicing'),
132
-		'AR' => __('Argentina', 'invoicing'),
133
-		'AM' => __('Armenia', 'invoicing'),
134
-		'AW' => __('Aruba', 'invoicing'),
135
-		'AU' => __('Australia', 'invoicing'),
136
-		'AT' => __('Austria', 'invoicing'),
137
-		'AZ' => __('Azerbaijan', 'invoicing'),
138
-		'BS' => __('Bahamas', 'invoicing'),
139
-		'BH' => __('Bahrain', 'invoicing'),
140
-		'BD' => __('Bangladesh', 'invoicing'),
141
-		'BB' => __('Barbados', 'invoicing'),
142
-		'BY' => __('Belarus', 'invoicing'),
143
-		'BE' => __('Belgium', 'invoicing'),
144
-		'BZ' => __('Belize', 'invoicing'),
145
-		'BJ' => __('Benin', 'invoicing'),
146
-		'BM' => __('Bermuda', 'invoicing'),
147
-		'BT' => __('Bhutan', 'invoicing'),
148
-		'BO' => __('Bolivia', 'invoicing'),
149
-		'BQ' => __('Bonaire, Saint Eustatius and Saba', 'invoicing'),
150
-		'BA' => __('Bosnia and Herzegovina', 'invoicing'),
151
-		'BW' => __('Botswana', 'invoicing'),
152
-		'BV' => __('Bouvet Island', 'invoicing'),
153
-		'BR' => __('Brazil', 'invoicing'),
154
-		'IO' => __('British Indian Ocean Territory', 'invoicing'),
155
-		'BN' => __('Brunei Darrussalam', 'invoicing'),
156
-		'BG' => __('Bulgaria', 'invoicing'),
157
-		'BF' => __('Burkina Faso', 'invoicing'),
158
-		'BI' => __('Burundi', 'invoicing'),
159
-		'KH' => __('Cambodia', 'invoicing'),
160
-		'CM' => __('Cameroon', 'invoicing'),
161
-		'CV' => __('Cape Verde', 'invoicing'),
162
-		'KY' => __('Cayman Islands', 'invoicing'),
163
-		'CF' => __('Central African Republic', 'invoicing'),
164
-		'TD' => __('Chad', 'invoicing'),
165
-		'CL' => __('Chile', 'invoicing'),
166
-		'CN' => __('China', 'invoicing'),
167
-		'CX' => __('Christmas Island', 'invoicing'),
168
-		'CC' => __('Cocos Islands', 'invoicing'),
169
-		'CO' => __('Colombia', 'invoicing'),
170
-		'KM' => __('Comoros', 'invoicing'),
171
-		'CD' => __('Congo, Democratic People\'s Republic', 'invoicing'),
172
-		'CG' => __('Congo, Republic of', 'invoicing'),
173
-		'CK' => __('Cook Islands', 'invoicing'),
174
-		'CR' => __('Costa Rica', 'invoicing'),
175
-		'CI' => __('Cote d\'Ivoire', 'invoicing'),
176
-		'HR' => __('Croatia/Hrvatska', 'invoicing'),
177
-		'CU' => __('Cuba', 'invoicing'),
178
-		'CW' => __('Cura&Ccedil;ao', 'invoicing'),
179
-		'CY' => __('Cyprus', 'invoicing'),
180
-		'CZ' => __('Czech Republic', 'invoicing'),
181
-		'DK' => __('Denmark', 'invoicing'),
182
-		'DJ' => __('Djibouti', 'invoicing'),
183
-		'DM' => __('Dominica', 'invoicing'),
184
-		'DO' => __('Dominican Republic', 'invoicing'),
185
-		'TP' => __('East Timor', 'invoicing'),
186
-		'EC' => __('Ecuador', 'invoicing'),
187
-		'EG' => __('Egypt', 'invoicing'),
188
-		'GQ' => __('Equatorial Guinea', 'invoicing'),
189
-		'SV' => __('El Salvador', 'invoicing'),
190
-		'ER' => __('Eritrea', 'invoicing'),
191
-		'EE' => __('Estonia', 'invoicing'),
192
-		'ET' => __('Ethiopia', 'invoicing'),
193
-		'FK' => __('Falkland Islands', 'invoicing'),
194
-		'FO' => __('Faroe Islands', 'invoicing'),
195
-		'FJ' => __('Fiji', 'invoicing'),
196
-		'FI' => __('Finland', 'invoicing'),
197
-		'FR' => __('France', 'invoicing'),
198
-		'GF' => __('French Guiana', 'invoicing'),
199
-		'PF' => __('French Polynesia', 'invoicing'),
200
-		'TF' => __('French Southern Territories', 'invoicing'),
201
-		'GA' => __('Gabon', 'invoicing'),
202
-		'GM' => __('Gambia', 'invoicing'),
203
-		'GE' => __('Georgia', 'invoicing'),
204
-		'DE' => __('Germany', 'invoicing'),
205
-		'GR' => __('Greece', 'invoicing'),
206
-		'GH' => __('Ghana', 'invoicing'),
207
-		'GI' => __('Gibraltar', 'invoicing'),
208
-		'GL' => __('Greenland', 'invoicing'),
209
-		'GD' => __('Grenada', 'invoicing'),
210
-		'GP' => __('Guadeloupe', 'invoicing'),
211
-		'GU' => __('Guam', 'invoicing'),
212
-		'GT' => __('Guatemala', 'invoicing'),
213
-		'GG' => __('Guernsey', 'invoicing'),
214
-		'GN' => __('Guinea', 'invoicing'),
215
-		'GW' => __('Guinea-Bissau', 'invoicing'),
216
-		'GY' => __('Guyana', 'invoicing'),
217
-		'HT' => __('Haiti', 'invoicing'),
218
-		'HM' => __('Heard and McDonald Islands', 'invoicing'),
219
-		'VA' => __('Holy See (City Vatican State)', 'invoicing'),
220
-		'HN' => __('Honduras', 'invoicing'),
221
-		'HK' => __('Hong Kong', 'invoicing'),
222
-		'HU' => __('Hungary', 'invoicing'),
223
-		'IS' => __('Iceland', 'invoicing'),
224
-		'IN' => __('India', 'invoicing'),
225
-		'ID' => __('Indonesia', 'invoicing'),
226
-		'IR' => __('Iran', 'invoicing'),
227
-		'IQ' => __('Iraq', 'invoicing'),
228
-		'IE' => __('Ireland', 'invoicing'),
229
-		'IM' => __('Isle of Man', 'invoicing'),
230
-		'IL' => __('Israel', 'invoicing'),
231
-		'IT' => __('Italy', 'invoicing'),
232
-		'JM' => __('Jamaica', 'invoicing'),
233
-		'JP' => __('Japan', 'invoicing'),
234
-		'JE' => __('Jersey', 'invoicing'),
235
-		'JO' => __('Jordan', 'invoicing'),
236
-		'KZ' => __('Kazakhstan', 'invoicing'),
237
-		'KE' => __('Kenya', 'invoicing'),
238
-		'KI' => __('Kiribati', 'invoicing'),
239
-		'KW' => __('Kuwait', 'invoicing'),
240
-		'KG' => __('Kyrgyzstan', 'invoicing'),
241
-		'LA' => __('Lao People\'s Democratic Republic', 'invoicing'),
242
-		'LV' => __('Latvia', 'invoicing'),
243
-		'LB' => __('Lebanon', 'invoicing'),
244
-		'LS' => __('Lesotho', 'invoicing'),
245
-		'LR' => __('Liberia', 'invoicing'),
246
-		'LY' => __('Libyan Arab Jamahiriya', 'invoicing'),
247
-		'LI' => __('Liechtenstein', 'invoicing'),
248
-		'LT' => __('Lithuania', 'invoicing'),
249
-		'LU' => __('Luxembourg', 'invoicing'),
250
-		'MO' => __('Macau', 'invoicing'),
251
-		'MK' => __('Macedonia', 'invoicing'),
252
-		'MG' => __('Madagascar', 'invoicing'),
253
-		'MW' => __('Malawi', 'invoicing'),
254
-		'MY' => __('Malaysia', 'invoicing'),
255
-		'MV' => __('Maldives', 'invoicing'),
256
-		'ML' => __('Mali', 'invoicing'),
257
-		'MT' => __('Malta', 'invoicing'),
258
-		'MH' => __('Marshall Islands', 'invoicing'),
259
-		'MQ' => __('Martinique', 'invoicing'),
260
-		'MR' => __('Mauritania', 'invoicing'),
261
-		'MU' => __('Mauritius', 'invoicing'),
262
-		'YT' => __('Mayotte', 'invoicing'),
263
-		'MX' => __('Mexico', 'invoicing'),
264
-		'FM' => __('Micronesia', 'invoicing'),
265
-		'MD' => __('Moldova, Republic of', 'invoicing'),
266
-		'MC' => __('Monaco', 'invoicing'),
267
-		'MN' => __('Mongolia', 'invoicing'),
268
-		'ME' => __('Montenegro', 'invoicing'),
269
-		'MS' => __('Montserrat', 'invoicing'),
270
-		'MA' => __('Morocco', 'invoicing'),
271
-		'MZ' => __('Mozambique', 'invoicing'),
272
-		'MM' => __('Myanmar', 'invoicing'),
273
-		'NA' => __('Namibia', 'invoicing'),
274
-		'NR' => __('Nauru', 'invoicing'),
275
-		'NP' => __('Nepal', 'invoicing'),
276
-		'NL' => __('Netherlands', 'invoicing'),
277
-		'AN' => __('Netherlands Antilles', 'invoicing'),
278
-		'NC' => __('New Caledonia', 'invoicing'),
279
-		'NZ' => __('New Zealand', 'invoicing'),
280
-		'NI' => __('Nicaragua', 'invoicing'),
281
-		'NE' => __('Niger', 'invoicing'),
282
-		'NG' => __('Nigeria', 'invoicing'),
283
-		'NU' => __('Niue', 'invoicing'),
284
-		'NF' => __('Norfolk Island', 'invoicing'),
285
-		'KP' => __('North Korea', 'invoicing'),
286
-		'MP' => __('Northern Mariana Islands', 'invoicing'),
287
-		'NO' => __('Norway', 'invoicing'),
288
-		'OM' => __('Oman', 'invoicing'),
289
-		'PK' => __('Pakistan', 'invoicing'),
290
-		'PW' => __('Palau', 'invoicing'),
291
-		'PS' => __('Palestinian Territories', 'invoicing'),
292
-		'PA' => __('Panama', 'invoicing'),
293
-		'PG' => __('Papua New Guinea', 'invoicing'),
294
-		'PY' => __('Paraguay', 'invoicing'),
295
-		'PE' => __('Peru', 'invoicing'),
296
-		'PH' => __('Phillipines', 'invoicing'),
297
-		'PN' => __('Pitcairn Island', 'invoicing'),
298
-		'PL' => __('Poland', 'invoicing'),
299
-		'PT' => __('Portugal', 'invoicing'),
300
-		'PR' => __('Puerto Rico', 'invoicing'),
301
-		'QA' => __('Qatar', 'invoicing'),
302
-		'XK' => __('Republic of Kosovo', 'invoicing'),
303
-		'RE' => __('Reunion Island', 'invoicing'),
304
-		'RO' => __('Romania', 'invoicing'),
305
-		'RU' => __('Russian Federation', 'invoicing'),
306
-		'RW' => __('Rwanda', 'invoicing'),
307
-		'BL' => __('Saint Barth&eacute;lemy', 'invoicing'),
308
-		'SH' => __('Saint Helena', 'invoicing'),
309
-		'KN' => __('Saint Kitts and Nevis', 'invoicing'),
310
-		'LC' => __('Saint Lucia', 'invoicing'),
311
-		'MF' => __('Saint Martin (French)', 'invoicing'),
312
-		'SX' => __('Saint Martin (Dutch)', 'invoicing'),
313
-		'PM' => __('Saint Pierre and Miquelon', 'invoicing'),
314
-		'VC' => __('Saint Vincent and the Grenadines', 'invoicing'),
315
-		'SM' => __('San Marino', 'invoicing'),
316
-		'ST' => __('S&atilde;o Tom&eacute; and Pr&iacute;ncipe', 'invoicing'),
317
-		'SA' => __('Saudi Arabia', 'invoicing'),
318
-		'SN' => __('Senegal', 'invoicing'),
319
-		'RS' => __('Serbia', 'invoicing'),
320
-		'SC' => __('Seychelles', 'invoicing'),
321
-		'SL' => __('Sierra Leone', 'invoicing'),
322
-		'SG' => __('Singapore', 'invoicing'),
323
-		'SK' => __('Slovak Republic', 'invoicing'),
324
-		'SI' => __('Slovenia', 'invoicing'),
325
-		'SB' => __('Solomon Islands', 'invoicing'),
326
-		'SO' => __('Somalia', 'invoicing'),
327
-		'ZA' => __('South Africa', 'invoicing'),
328
-		'GS' => __('South Georgia', 'invoicing'),
329
-		'KR' => __('South Korea', 'invoicing'),
330
-		'SS' => __('South Sudan', 'invoicing'),
331
-		'ES' => __('Spain', 'invoicing'),
332
-		'LK' => __('Sri Lanka', 'invoicing'),
333
-		'SD' => __('Sudan', 'invoicing'),
334
-		'SR' => __('Suriname', 'invoicing'),
335
-		'SJ' => __('Svalbard and Jan Mayen Islands', 'invoicing'),
336
-		'SZ' => __('Swaziland', 'invoicing'),
337
-		'SE' => __('Sweden', 'invoicing'),
338
-		'CH' => __('Switzerland', 'invoicing'),
339
-		'SY' => __('Syrian Arab Republic', 'invoicing'),
340
-		'TW' => __('Taiwan', 'invoicing'),
341
-		'TJ' => __('Tajikistan', 'invoicing'),
342
-		'TZ' => __('Tanzania', 'invoicing'),
343
-		'TH' => __('Thailand', 'invoicing'),
344
-		'TL' => __('Timor-Leste', 'invoicing'),
345
-		'TG' => __('Togo', 'invoicing'),
346
-		'TK' => __('Tokelau', 'invoicing'),
347
-		'TO' => __('Tonga', 'invoicing'),
348
-		'TT' => __('Trinidad and Tobago', 'invoicing'),
349
-		'TN' => __('Tunisia', 'invoicing'),
350
-		'TR' => __('Turkey', 'invoicing'),
351
-		'TM' => __('Turkmenistan', 'invoicing'),
352
-		'TC' => __('Turks and Caicos Islands', 'invoicing'),
353
-		'TV' => __('Tuvalu', 'invoicing'),
354
-		'UG' => __('Uganda', 'invoicing'),
355
-		'UA' => __('Ukraine', 'invoicing'),
356
-		'AE' => __('United Arab Emirates', 'invoicing'),
357
-		'UY' => __('Uruguay', 'invoicing'),
358
-		'UM' => __('US Minor Outlying Islands', 'invoicing'),
359
-		'UZ' => __('Uzbekistan', 'invoicing'),
360
-		'VU' => __('Vanuatu', 'invoicing'),
361
-		'VE' => __('Venezuela', 'invoicing'),
362
-		'VN' => __('Vietnam', 'invoicing'),
363
-		'VG' => __('Virgin Islands (British)', 'invoicing'),
364
-		'VI' => __('Virgin Islands (USA)', 'invoicing'),
365
-		'WF' => __('Wallis and Futuna Islands', 'invoicing'),
366
-		'EH' => __('Western Sahara', 'invoicing'),
367
-		'WS' => __('Western Samoa', 'invoicing'),
368
-		'YE' => __('Yemen', 'invoicing'),
369
-		'ZM' => __('Zambia', 'invoicing'),
370
-		'ZW' => __('Zimbabwe', 'invoicing'),
371
-	);
118
+    $countries = array(
119
+        'US' => __('United States', 'invoicing'),
120
+        'CA' => __('Canada', 'invoicing'),
121
+        'GB' => __('United Kingdom', 'invoicing'),
122
+        'AF' => __('Afghanistan', 'invoicing'),
123
+        'AX' => __('Aland Islands', 'invoicing'),
124
+        'AL' => __('Albania', 'invoicing'),
125
+        'DZ' => __('Algeria', 'invoicing'),
126
+        'AS' => __('American Samoa', 'invoicing'),
127
+        'AD' => __('Andorra', 'invoicing'),
128
+        'AO' => __('Angola', 'invoicing'),
129
+        'AI' => __('Anguilla', 'invoicing'),
130
+        'AQ' => __('Antarctica', 'invoicing'),
131
+        'AG' => __('Antigua and Barbuda', 'invoicing'),
132
+        'AR' => __('Argentina', 'invoicing'),
133
+        'AM' => __('Armenia', 'invoicing'),
134
+        'AW' => __('Aruba', 'invoicing'),
135
+        'AU' => __('Australia', 'invoicing'),
136
+        'AT' => __('Austria', 'invoicing'),
137
+        'AZ' => __('Azerbaijan', 'invoicing'),
138
+        'BS' => __('Bahamas', 'invoicing'),
139
+        'BH' => __('Bahrain', 'invoicing'),
140
+        'BD' => __('Bangladesh', 'invoicing'),
141
+        'BB' => __('Barbados', 'invoicing'),
142
+        'BY' => __('Belarus', 'invoicing'),
143
+        'BE' => __('Belgium', 'invoicing'),
144
+        'BZ' => __('Belize', 'invoicing'),
145
+        'BJ' => __('Benin', 'invoicing'),
146
+        'BM' => __('Bermuda', 'invoicing'),
147
+        'BT' => __('Bhutan', 'invoicing'),
148
+        'BO' => __('Bolivia', 'invoicing'),
149
+        'BQ' => __('Bonaire, Saint Eustatius and Saba', 'invoicing'),
150
+        'BA' => __('Bosnia and Herzegovina', 'invoicing'),
151
+        'BW' => __('Botswana', 'invoicing'),
152
+        'BV' => __('Bouvet Island', 'invoicing'),
153
+        'BR' => __('Brazil', 'invoicing'),
154
+        'IO' => __('British Indian Ocean Territory', 'invoicing'),
155
+        'BN' => __('Brunei Darrussalam', 'invoicing'),
156
+        'BG' => __('Bulgaria', 'invoicing'),
157
+        'BF' => __('Burkina Faso', 'invoicing'),
158
+        'BI' => __('Burundi', 'invoicing'),
159
+        'KH' => __('Cambodia', 'invoicing'),
160
+        'CM' => __('Cameroon', 'invoicing'),
161
+        'CV' => __('Cape Verde', 'invoicing'),
162
+        'KY' => __('Cayman Islands', 'invoicing'),
163
+        'CF' => __('Central African Republic', 'invoicing'),
164
+        'TD' => __('Chad', 'invoicing'),
165
+        'CL' => __('Chile', 'invoicing'),
166
+        'CN' => __('China', 'invoicing'),
167
+        'CX' => __('Christmas Island', 'invoicing'),
168
+        'CC' => __('Cocos Islands', 'invoicing'),
169
+        'CO' => __('Colombia', 'invoicing'),
170
+        'KM' => __('Comoros', 'invoicing'),
171
+        'CD' => __('Congo, Democratic People\'s Republic', 'invoicing'),
172
+        'CG' => __('Congo, Republic of', 'invoicing'),
173
+        'CK' => __('Cook Islands', 'invoicing'),
174
+        'CR' => __('Costa Rica', 'invoicing'),
175
+        'CI' => __('Cote d\'Ivoire', 'invoicing'),
176
+        'HR' => __('Croatia/Hrvatska', 'invoicing'),
177
+        'CU' => __('Cuba', 'invoicing'),
178
+        'CW' => __('Cura&Ccedil;ao', 'invoicing'),
179
+        'CY' => __('Cyprus', 'invoicing'),
180
+        'CZ' => __('Czech Republic', 'invoicing'),
181
+        'DK' => __('Denmark', 'invoicing'),
182
+        'DJ' => __('Djibouti', 'invoicing'),
183
+        'DM' => __('Dominica', 'invoicing'),
184
+        'DO' => __('Dominican Republic', 'invoicing'),
185
+        'TP' => __('East Timor', 'invoicing'),
186
+        'EC' => __('Ecuador', 'invoicing'),
187
+        'EG' => __('Egypt', 'invoicing'),
188
+        'GQ' => __('Equatorial Guinea', 'invoicing'),
189
+        'SV' => __('El Salvador', 'invoicing'),
190
+        'ER' => __('Eritrea', 'invoicing'),
191
+        'EE' => __('Estonia', 'invoicing'),
192
+        'ET' => __('Ethiopia', 'invoicing'),
193
+        'FK' => __('Falkland Islands', 'invoicing'),
194
+        'FO' => __('Faroe Islands', 'invoicing'),
195
+        'FJ' => __('Fiji', 'invoicing'),
196
+        'FI' => __('Finland', 'invoicing'),
197
+        'FR' => __('France', 'invoicing'),
198
+        'GF' => __('French Guiana', 'invoicing'),
199
+        'PF' => __('French Polynesia', 'invoicing'),
200
+        'TF' => __('French Southern Territories', 'invoicing'),
201
+        'GA' => __('Gabon', 'invoicing'),
202
+        'GM' => __('Gambia', 'invoicing'),
203
+        'GE' => __('Georgia', 'invoicing'),
204
+        'DE' => __('Germany', 'invoicing'),
205
+        'GR' => __('Greece', 'invoicing'),
206
+        'GH' => __('Ghana', 'invoicing'),
207
+        'GI' => __('Gibraltar', 'invoicing'),
208
+        'GL' => __('Greenland', 'invoicing'),
209
+        'GD' => __('Grenada', 'invoicing'),
210
+        'GP' => __('Guadeloupe', 'invoicing'),
211
+        'GU' => __('Guam', 'invoicing'),
212
+        'GT' => __('Guatemala', 'invoicing'),
213
+        'GG' => __('Guernsey', 'invoicing'),
214
+        'GN' => __('Guinea', 'invoicing'),
215
+        'GW' => __('Guinea-Bissau', 'invoicing'),
216
+        'GY' => __('Guyana', 'invoicing'),
217
+        'HT' => __('Haiti', 'invoicing'),
218
+        'HM' => __('Heard and McDonald Islands', 'invoicing'),
219
+        'VA' => __('Holy See (City Vatican State)', 'invoicing'),
220
+        'HN' => __('Honduras', 'invoicing'),
221
+        'HK' => __('Hong Kong', 'invoicing'),
222
+        'HU' => __('Hungary', 'invoicing'),
223
+        'IS' => __('Iceland', 'invoicing'),
224
+        'IN' => __('India', 'invoicing'),
225
+        'ID' => __('Indonesia', 'invoicing'),
226
+        'IR' => __('Iran', 'invoicing'),
227
+        'IQ' => __('Iraq', 'invoicing'),
228
+        'IE' => __('Ireland', 'invoicing'),
229
+        'IM' => __('Isle of Man', 'invoicing'),
230
+        'IL' => __('Israel', 'invoicing'),
231
+        'IT' => __('Italy', 'invoicing'),
232
+        'JM' => __('Jamaica', 'invoicing'),
233
+        'JP' => __('Japan', 'invoicing'),
234
+        'JE' => __('Jersey', 'invoicing'),
235
+        'JO' => __('Jordan', 'invoicing'),
236
+        'KZ' => __('Kazakhstan', 'invoicing'),
237
+        'KE' => __('Kenya', 'invoicing'),
238
+        'KI' => __('Kiribati', 'invoicing'),
239
+        'KW' => __('Kuwait', 'invoicing'),
240
+        'KG' => __('Kyrgyzstan', 'invoicing'),
241
+        'LA' => __('Lao People\'s Democratic Republic', 'invoicing'),
242
+        'LV' => __('Latvia', 'invoicing'),
243
+        'LB' => __('Lebanon', 'invoicing'),
244
+        'LS' => __('Lesotho', 'invoicing'),
245
+        'LR' => __('Liberia', 'invoicing'),
246
+        'LY' => __('Libyan Arab Jamahiriya', 'invoicing'),
247
+        'LI' => __('Liechtenstein', 'invoicing'),
248
+        'LT' => __('Lithuania', 'invoicing'),
249
+        'LU' => __('Luxembourg', 'invoicing'),
250
+        'MO' => __('Macau', 'invoicing'),
251
+        'MK' => __('Macedonia', 'invoicing'),
252
+        'MG' => __('Madagascar', 'invoicing'),
253
+        'MW' => __('Malawi', 'invoicing'),
254
+        'MY' => __('Malaysia', 'invoicing'),
255
+        'MV' => __('Maldives', 'invoicing'),
256
+        'ML' => __('Mali', 'invoicing'),
257
+        'MT' => __('Malta', 'invoicing'),
258
+        'MH' => __('Marshall Islands', 'invoicing'),
259
+        'MQ' => __('Martinique', 'invoicing'),
260
+        'MR' => __('Mauritania', 'invoicing'),
261
+        'MU' => __('Mauritius', 'invoicing'),
262
+        'YT' => __('Mayotte', 'invoicing'),
263
+        'MX' => __('Mexico', 'invoicing'),
264
+        'FM' => __('Micronesia', 'invoicing'),
265
+        'MD' => __('Moldova, Republic of', 'invoicing'),
266
+        'MC' => __('Monaco', 'invoicing'),
267
+        'MN' => __('Mongolia', 'invoicing'),
268
+        'ME' => __('Montenegro', 'invoicing'),
269
+        'MS' => __('Montserrat', 'invoicing'),
270
+        'MA' => __('Morocco', 'invoicing'),
271
+        'MZ' => __('Mozambique', 'invoicing'),
272
+        'MM' => __('Myanmar', 'invoicing'),
273
+        'NA' => __('Namibia', 'invoicing'),
274
+        'NR' => __('Nauru', 'invoicing'),
275
+        'NP' => __('Nepal', 'invoicing'),
276
+        'NL' => __('Netherlands', 'invoicing'),
277
+        'AN' => __('Netherlands Antilles', 'invoicing'),
278
+        'NC' => __('New Caledonia', 'invoicing'),
279
+        'NZ' => __('New Zealand', 'invoicing'),
280
+        'NI' => __('Nicaragua', 'invoicing'),
281
+        'NE' => __('Niger', 'invoicing'),
282
+        'NG' => __('Nigeria', 'invoicing'),
283
+        'NU' => __('Niue', 'invoicing'),
284
+        'NF' => __('Norfolk Island', 'invoicing'),
285
+        'KP' => __('North Korea', 'invoicing'),
286
+        'MP' => __('Northern Mariana Islands', 'invoicing'),
287
+        'NO' => __('Norway', 'invoicing'),
288
+        'OM' => __('Oman', 'invoicing'),
289
+        'PK' => __('Pakistan', 'invoicing'),
290
+        'PW' => __('Palau', 'invoicing'),
291
+        'PS' => __('Palestinian Territories', 'invoicing'),
292
+        'PA' => __('Panama', 'invoicing'),
293
+        'PG' => __('Papua New Guinea', 'invoicing'),
294
+        'PY' => __('Paraguay', 'invoicing'),
295
+        'PE' => __('Peru', 'invoicing'),
296
+        'PH' => __('Phillipines', 'invoicing'),
297
+        'PN' => __('Pitcairn Island', 'invoicing'),
298
+        'PL' => __('Poland', 'invoicing'),
299
+        'PT' => __('Portugal', 'invoicing'),
300
+        'PR' => __('Puerto Rico', 'invoicing'),
301
+        'QA' => __('Qatar', 'invoicing'),
302
+        'XK' => __('Republic of Kosovo', 'invoicing'),
303
+        'RE' => __('Reunion Island', 'invoicing'),
304
+        'RO' => __('Romania', 'invoicing'),
305
+        'RU' => __('Russian Federation', 'invoicing'),
306
+        'RW' => __('Rwanda', 'invoicing'),
307
+        'BL' => __('Saint Barth&eacute;lemy', 'invoicing'),
308
+        'SH' => __('Saint Helena', 'invoicing'),
309
+        'KN' => __('Saint Kitts and Nevis', 'invoicing'),
310
+        'LC' => __('Saint Lucia', 'invoicing'),
311
+        'MF' => __('Saint Martin (French)', 'invoicing'),
312
+        'SX' => __('Saint Martin (Dutch)', 'invoicing'),
313
+        'PM' => __('Saint Pierre and Miquelon', 'invoicing'),
314
+        'VC' => __('Saint Vincent and the Grenadines', 'invoicing'),
315
+        'SM' => __('San Marino', 'invoicing'),
316
+        'ST' => __('S&atilde;o Tom&eacute; and Pr&iacute;ncipe', 'invoicing'),
317
+        'SA' => __('Saudi Arabia', 'invoicing'),
318
+        'SN' => __('Senegal', 'invoicing'),
319
+        'RS' => __('Serbia', 'invoicing'),
320
+        'SC' => __('Seychelles', 'invoicing'),
321
+        'SL' => __('Sierra Leone', 'invoicing'),
322
+        'SG' => __('Singapore', 'invoicing'),
323
+        'SK' => __('Slovak Republic', 'invoicing'),
324
+        'SI' => __('Slovenia', 'invoicing'),
325
+        'SB' => __('Solomon Islands', 'invoicing'),
326
+        'SO' => __('Somalia', 'invoicing'),
327
+        'ZA' => __('South Africa', 'invoicing'),
328
+        'GS' => __('South Georgia', 'invoicing'),
329
+        'KR' => __('South Korea', 'invoicing'),
330
+        'SS' => __('South Sudan', 'invoicing'),
331
+        'ES' => __('Spain', 'invoicing'),
332
+        'LK' => __('Sri Lanka', 'invoicing'),
333
+        'SD' => __('Sudan', 'invoicing'),
334
+        'SR' => __('Suriname', 'invoicing'),
335
+        'SJ' => __('Svalbard and Jan Mayen Islands', 'invoicing'),
336
+        'SZ' => __('Swaziland', 'invoicing'),
337
+        'SE' => __('Sweden', 'invoicing'),
338
+        'CH' => __('Switzerland', 'invoicing'),
339
+        'SY' => __('Syrian Arab Republic', 'invoicing'),
340
+        'TW' => __('Taiwan', 'invoicing'),
341
+        'TJ' => __('Tajikistan', 'invoicing'),
342
+        'TZ' => __('Tanzania', 'invoicing'),
343
+        'TH' => __('Thailand', 'invoicing'),
344
+        'TL' => __('Timor-Leste', 'invoicing'),
345
+        'TG' => __('Togo', 'invoicing'),
346
+        'TK' => __('Tokelau', 'invoicing'),
347
+        'TO' => __('Tonga', 'invoicing'),
348
+        'TT' => __('Trinidad and Tobago', 'invoicing'),
349
+        'TN' => __('Tunisia', 'invoicing'),
350
+        'TR' => __('Turkey', 'invoicing'),
351
+        'TM' => __('Turkmenistan', 'invoicing'),
352
+        'TC' => __('Turks and Caicos Islands', 'invoicing'),
353
+        'TV' => __('Tuvalu', 'invoicing'),
354
+        'UG' => __('Uganda', 'invoicing'),
355
+        'UA' => __('Ukraine', 'invoicing'),
356
+        'AE' => __('United Arab Emirates', 'invoicing'),
357
+        'UY' => __('Uruguay', 'invoicing'),
358
+        'UM' => __('US Minor Outlying Islands', 'invoicing'),
359
+        'UZ' => __('Uzbekistan', 'invoicing'),
360
+        'VU' => __('Vanuatu', 'invoicing'),
361
+        'VE' => __('Venezuela', 'invoicing'),
362
+        'VN' => __('Vietnam', 'invoicing'),
363
+        'VG' => __('Virgin Islands (British)', 'invoicing'),
364
+        'VI' => __('Virgin Islands (USA)', 'invoicing'),
365
+        'WF' => __('Wallis and Futuna Islands', 'invoicing'),
366
+        'EH' => __('Western Sahara', 'invoicing'),
367
+        'WS' => __('Western Samoa', 'invoicing'),
368
+        'YE' => __('Yemen', 'invoicing'),
369
+        'ZM' => __('Zambia', 'invoicing'),
370
+        'ZW' => __('Zimbabwe', 'invoicing'),
371
+    );
372 372
     
373 373
     if ( $first_empty ) {
374 374
         $countries = array_merge( array( '' => '' ), $countries );
@@ -1537,30 +1537,30 @@  discard block
 block discarded – undo
1537 1537
 }
1538 1538
 
1539 1539
 function wpinv_get_states_field() {
1540
-	if( empty( $_POST['country'] ) ) {
1541
-		$_POST['country'] = wpinv_get_default_country();
1542
-	}
1543
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
1540
+    if( empty( $_POST['country'] ) ) {
1541
+        $_POST['country'] = wpinv_get_default_country();
1542
+    }
1543
+    $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
1544 1544
 
1545
-	if( !empty( $states ) ) {
1546
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
1545
+    if( !empty( $states ) ) {
1546
+        $sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
1547 1547
         
1548 1548
         $args = array(
1549
-			'name'    => $sanitized_field_name,
1550
-			'id'      => $sanitized_field_name,
1551
-			'class'   => $sanitized_field_name . ' wpinv-select',
1552
-			'options' => array_merge( array( '' => '' ), $states ),
1553
-			'show_option_all'  => false,
1554
-			'show_option_none' => false
1555
-		);
1556
-
1557
-		$response = wpinv_html_select( $args );
1558
-
1559
-	} else {
1560
-		$response = 'nostates';
1561
-	}
1549
+            'name'    => $sanitized_field_name,
1550
+            'id'      => $sanitized_field_name,
1551
+            'class'   => $sanitized_field_name . ' wpinv-select',
1552
+            'options' => array_merge( array( '' => '' ), $states ),
1553
+            'show_option_all'  => false,
1554
+            'show_option_none' => false
1555
+        );
1556
+
1557
+        $response = wpinv_html_select( $args );
1558
+
1559
+    } else {
1560
+        $response = 'nostates';
1561
+    }
1562 1562
 
1563
-	return $response;
1563
+    return $response;
1564 1564
 }
1565 1565
 
1566 1566
 function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
Please login to merge, or discard this patch.
Spacing   +979 added lines, -979 removed lines patch added patch discarded remove patch
@@ -7,67 +7,67 @@  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
-function wpinv_is_base_country( $country ) {
21
+function wpinv_is_base_country($country) {
22 22
     $base_country = wpinv_get_default_country();
23 23
     
24
-    if ( $base_country === 'UK' ) {
24
+    if ($base_country === 'UK') {
25 25
         $base_country = 'GB';
26 26
     }
27
-    if ( $country == 'UK' ) {
27
+    if ($country == 'UK') {
28 28
         $country = 'GB';
29 29
     }
30 30
 
31
-    return ( $country && $country === $base_country ) ? true : false;
31
+    return ($country && $country === $base_country) ? true : false;
32 32
 }
33 33
 
34
-function wpinv_country_name( $country_code = '' ) { 
34
+function wpinv_country_name($country_code = '') { 
35 35
     $countries = wpinv_get_country_list();
36 36
     $country_code = $country_code == 'UK' ? 'GB' : $country_code;
37
-    $country = isset( $countries[$country_code] ) ? $countries[$country_code] : $country_code;
37
+    $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code;
38 38
 
39
-    return apply_filters( 'wpinv_country_name', $country, $country_code );
39
+    return apply_filters('wpinv_country_name', $country, $country_code);
40 40
 }
41 41
 
42 42
 function wpinv_get_default_state() {
43
-	$state = wpinv_get_option( 'default_state', false );
43
+	$state = wpinv_get_option('default_state', false);
44 44
 
45
-	return apply_filters( 'wpinv_default_state', $state );
45
+	return apply_filters('wpinv_default_state', $state);
46 46
 }
47 47
 
48
-function wpinv_state_name( $state_code = '', $country_code = '' ) {
48
+function wpinv_state_name($state_code = '', $country_code = '') {
49 49
     $state = $state_code;
50 50
     
51
-    if ( !empty( $country_code ) ) {
52
-        $states = wpinv_get_country_states( $country_code );
51
+    if (!empty($country_code)) {
52
+        $states = wpinv_get_country_states($country_code);
53 53
         
54
-        $state = !empty( $states ) && isset( $states[$state_code] ) ? $states[$state_code] : $state;
54
+        $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state;
55 55
     }
56 56
 
57
-    return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code );
57
+    return apply_filters('wpinv_state_name', $state, $state_code, $country_code);
58 58
 }
59 59
 
60 60
 function wpinv_store_address() {
61
-    $address = wpinv_get_option( 'store_address', '' );
61
+    $address = wpinv_get_option('store_address', '');
62 62
 
63
-    return apply_filters( 'wpinv_store_address', $address );
63
+    return apply_filters('wpinv_store_address', $address);
64 64
 }
65 65
 
66
-function wpinv_get_user_address( $user_id = 0, $with_default = true ) {
66
+function wpinv_get_user_address($user_id = 0, $with_default = true) {
67 67
     global $wpi_userID;
68 68
     
69
-    if( empty( $user_id ) ) {
70
-        $user_id = !empty( $wpi_userID ) ? $wpi_userID : get_current_user_id();
69
+    if (empty($user_id)) {
70
+        $user_id = !empty($wpi_userID) ? $wpi_userID : get_current_user_id();
71 71
     }
72 72
     
73 73
     $address_fields = array(
@@ -85,36 +85,36 @@  discard block
 block discarded – undo
85 85
         'zip',
86 86
     );
87 87
     
88
-    $user_info = get_userdata( $user_id );
88
+    $user_info = get_userdata($user_id);
89 89
     
90 90
     $address = array();
91 91
     $address['user_id'] = $user_id;
92
-    $address['email'] = !empty( $user_info ) ? $user_info->user_email : '';
93
-    foreach ( $address_fields as $field ) {
94
-        $address[$field] = get_user_meta( $user_id, '_wpinv_' . $field, true );
92
+    $address['email'] = !empty($user_info) ? $user_info->user_email : '';
93
+    foreach ($address_fields as $field) {
94
+        $address[$field] = get_user_meta($user_id, '_wpinv_' . $field, true);
95 95
     }
96 96
 
97
-    if ( !empty( $user_info ) ) {
98
-        if( empty( $address['first_name'] ) )
97
+    if (!empty($user_info)) {
98
+        if (empty($address['first_name']))
99 99
             $address['first_name'] = $user_info->first_name;
100 100
         
101
-        if( empty( $address['last_name'] ) )
101
+        if (empty($address['last_name']))
102 102
             $address['last_name'] = $user_info->last_name;
103 103
     }
104 104
     
105
-    $address['name'] = trim( trim( $address['first_name'] . ' ' . $address['last_name'] ), "," );
105
+    $address['name'] = trim(trim($address['first_name'] . ' ' . $address['last_name']), ",");
106 106
     
107
-    if( empty( $address['state'] ) && $with_default )
107
+    if (empty($address['state']) && $with_default)
108 108
         $address['state'] = wpinv_get_default_state();
109 109
 
110
-    if( empty( $address['country'] ) && $with_default )
110
+    if (empty($address['country']) && $with_default)
111 111
         $address['country'] = wpinv_get_default_country();
112 112
 
113 113
 
114 114
     return $address;
115 115
 }
116 116
 
117
-function wpinv_get_country_list( $first_empty = false ) {
117
+function wpinv_get_country_list($first_empty = false) {
118 118
 	$countries = array(
119 119
 		'US' => __('United States', 'invoicing'),
120 120
 		'CA' => __('Canada', 'invoicing'),
@@ -370,23 +370,23 @@  discard block
 block discarded – undo
370 370
 		'ZW' => __('Zimbabwe', 'invoicing'),
371 371
 	);
372 372
     
373
-    if ( $first_empty ) {
374
-        $countries = array_merge( array( '' => '' ), $countries );
373
+    if ($first_empty) {
374
+        $countries = array_merge(array('' => ''), $countries);
375 375
     }
376 376
     
377
-    $countries = apply_filters( 'wpinv_countries', $countries );
377
+    $countries = apply_filters('wpinv_countries', $countries);
378 378
     
379 379
     asort($countries);
380 380
 
381 381
     return $countries;
382 382
 }
383 383
 
384
-function wpinv_get_country_states( $country = null, $first_empty = false ) {
385
-    if ( empty( $country ) ) {
384
+function wpinv_get_country_states($country = null, $first_empty = false) {
385
+    if (empty($country)) {
386 386
         $country = wpinv_get_default_country();
387 387
     }
388 388
 
389
-    switch( $country ) {
389
+    switch ($country) {
390 390
         case 'US' :
391 391
             $states = wpinv_get_us_states_list();
392 392
             break;
@@ -461,11 +461,11 @@  discard block
 block discarded – undo
461 461
             break;
462 462
     }
463 463
     
464
-    if ( !empty( $states ) && $first_empty ) {
465
-        $states = array_merge( array( '' => '' ), $states );
464
+    if (!empty($states) && $first_empty) {
465
+        $states = array_merge(array('' => ''), $states);
466 466
     }
467 467
     
468
-    $states = apply_filters( 'wpinv_country_states', $states, $country );
468
+    $states = apply_filters('wpinv_country_states', $states, $country);
469 469
     
470 470
     asort($states);
471 471
 
@@ -474,1087 +474,1087 @@  discard block
 block discarded – undo
474 474
 
475 475
 function wpinv_get_us_states_list() {
476 476
     $states = array(
477
-        'AL' => __( 'Alabama', 'invoicing' ),
478
-        'AK' => __( 'Alaska', 'invoicing' ),
479
-        'AZ' => __( 'Arizona', 'invoicing' ),
480
-        'AR' => __( 'Arkansas', 'invoicing' ),
481
-        'CA' => __( 'California', 'invoicing' ),
482
-        'CO' => __( 'Colorado', 'invoicing' ),
483
-        'CT' => __( 'Connecticut', 'invoicing' ),
484
-        'DE' => __( 'Delaware', 'invoicing' ),
485
-        'DC' => __( 'District of Columbia', 'invoicing' ),
486
-        'FL' => __( 'Florida', 'invoicing' ),
487
-        'GA' => __( 'Georgia', 'invoicing' ),
488
-        'HI' => __( 'Hawaii', 'invoicing' ),
489
-        'ID' => __( 'Idaho', 'invoicing' ),
490
-        'IL' => __( 'Illinois', 'invoicing' ),
491
-        'IN' => __( 'Indiana', 'invoicing' ),
492
-        'IA' => __( 'Iowa', 'invoicing' ),
493
-        'KS' => __( 'Kansas', 'invoicing' ),
494
-        'KY' => __( 'Kentucky', 'invoicing' ),
495
-        'LA' => __( 'Louisiana', 'invoicing' ),
496
-        'ME' => __( 'Maine', 'invoicing' ),
497
-        'MD' => __( 'Maryland', 'invoicing' ),
498
-        'MA' => __( 'Massachusetts', 'invoicing' ),
499
-        'MI' => __( 'Michigan', 'invoicing' ),
500
-        'MN' => __( 'Minnesota', 'invoicing' ),
501
-        'MS' => __( 'Mississippi', 'invoicing' ),
502
-        'MO' => __( 'Missouri', 'invoicing' ),
503
-        'MT' => __( 'Montana', 'invoicing' ),
504
-        'NE' => __( 'Nebraska', 'invoicing' ),
505
-        'NV' => __( 'Nevada', 'invoicing' ),
506
-        'NH' => __( 'New Hampshire', 'invoicing' ),
507
-        'NJ' => __( 'New Jersey', 'invoicing' ),
508
-        'NM' => __( 'New Mexico', 'invoicing' ),
509
-        'NY' => __( 'New York', 'invoicing' ),
510
-        'NC' => __( 'North Carolina', 'invoicing' ),
511
-        'ND' => __( 'North Dakota', 'invoicing' ),
512
-        'OH' => __( 'Ohio', 'invoicing' ),
513
-        'OK' => __( 'Oklahoma', 'invoicing' ),
514
-        'OR' => __( 'Oregon', 'invoicing' ),
515
-        'PA' => __( 'Pennsylvania', 'invoicing' ),
516
-        'RI' => __( 'Rhode Island', 'invoicing' ),
517
-        'SC' => __( 'South Carolina', 'invoicing' ),
518
-        'SD' => __( 'South Dakota', 'invoicing' ),
519
-        'TN' => __( 'Tennessee', 'invoicing' ),
520
-        'TX' => __( 'Texas', 'invoicing' ),
521
-        'UT' => __( 'Utah', 'invoicing' ),
522
-        'VT' => __( 'Vermont', 'invoicing' ),
523
-        'VA' => __( 'Virginia', 'invoicing' ),
524
-        'WA' => __( 'Washington', 'invoicing' ),
525
-        'WV' => __( 'West Virginia', 'invoicing' ),
526
-        'WI' => __( 'Wisconsin', 'invoicing' ),
527
-        'WY' => __( 'Wyoming', 'invoicing' ),
528
-        'AS' => __( 'American Samoa', 'invoicing' ),
529
-        'CZ' => __( 'Canal Zone', 'invoicing' ),
530
-        'CM' => __( 'Commonwealth of the Northern Mariana Islands', 'invoicing' ),
531
-        'FM' => __( 'Federated States of Micronesia', 'invoicing' ),
532
-        'GU' => __( 'Guam', 'invoicing' ),
533
-        'MH' => __( 'Marshall Islands', 'invoicing' ),
534
-        'MP' => __( 'Northern Mariana Islands', 'invoicing' ),
535
-        'PW' => __( 'Palau', 'invoicing' ),
536
-        'PI' => __( 'Philippine Islands', 'invoicing' ),
537
-        'PR' => __( 'Puerto Rico', 'invoicing' ),
538
-        'TT' => __( 'Trust Territory of the Pacific Islands', 'invoicing' ),
539
-        'VI' => __( 'Virgin Islands', 'invoicing' ),
540
-        'AA' => __( 'Armed Forces - Americas', 'invoicing' ),
541
-        'AE' => __( 'Armed Forces - Europe, Canada, Middle East, Africa', 'invoicing' ),
542
-        'AP' => __( 'Armed Forces - Pacific', 'invoicing' )
477
+        'AL' => __('Alabama', 'invoicing'),
478
+        'AK' => __('Alaska', 'invoicing'),
479
+        'AZ' => __('Arizona', 'invoicing'),
480
+        'AR' => __('Arkansas', 'invoicing'),
481
+        'CA' => __('California', 'invoicing'),
482
+        'CO' => __('Colorado', 'invoicing'),
483
+        'CT' => __('Connecticut', 'invoicing'),
484
+        'DE' => __('Delaware', 'invoicing'),
485
+        'DC' => __('District of Columbia', 'invoicing'),
486
+        'FL' => __('Florida', 'invoicing'),
487
+        'GA' => __('Georgia', 'invoicing'),
488
+        'HI' => __('Hawaii', 'invoicing'),
489
+        'ID' => __('Idaho', 'invoicing'),
490
+        'IL' => __('Illinois', 'invoicing'),
491
+        'IN' => __('Indiana', 'invoicing'),
492
+        'IA' => __('Iowa', 'invoicing'),
493
+        'KS' => __('Kansas', 'invoicing'),
494
+        'KY' => __('Kentucky', 'invoicing'),
495
+        'LA' => __('Louisiana', 'invoicing'),
496
+        'ME' => __('Maine', 'invoicing'),
497
+        'MD' => __('Maryland', 'invoicing'),
498
+        'MA' => __('Massachusetts', 'invoicing'),
499
+        'MI' => __('Michigan', 'invoicing'),
500
+        'MN' => __('Minnesota', 'invoicing'),
501
+        'MS' => __('Mississippi', 'invoicing'),
502
+        'MO' => __('Missouri', 'invoicing'),
503
+        'MT' => __('Montana', 'invoicing'),
504
+        'NE' => __('Nebraska', 'invoicing'),
505
+        'NV' => __('Nevada', 'invoicing'),
506
+        'NH' => __('New Hampshire', 'invoicing'),
507
+        'NJ' => __('New Jersey', 'invoicing'),
508
+        'NM' => __('New Mexico', 'invoicing'),
509
+        'NY' => __('New York', 'invoicing'),
510
+        'NC' => __('North Carolina', 'invoicing'),
511
+        'ND' => __('North Dakota', 'invoicing'),
512
+        'OH' => __('Ohio', 'invoicing'),
513
+        'OK' => __('Oklahoma', 'invoicing'),
514
+        'OR' => __('Oregon', 'invoicing'),
515
+        'PA' => __('Pennsylvania', 'invoicing'),
516
+        'RI' => __('Rhode Island', 'invoicing'),
517
+        'SC' => __('South Carolina', 'invoicing'),
518
+        'SD' => __('South Dakota', 'invoicing'),
519
+        'TN' => __('Tennessee', 'invoicing'),
520
+        'TX' => __('Texas', 'invoicing'),
521
+        'UT' => __('Utah', 'invoicing'),
522
+        'VT' => __('Vermont', 'invoicing'),
523
+        'VA' => __('Virginia', 'invoicing'),
524
+        'WA' => __('Washington', 'invoicing'),
525
+        'WV' => __('West Virginia', 'invoicing'),
526
+        'WI' => __('Wisconsin', 'invoicing'),
527
+        'WY' => __('Wyoming', 'invoicing'),
528
+        'AS' => __('American Samoa', 'invoicing'),
529
+        'CZ' => __('Canal Zone', 'invoicing'),
530
+        'CM' => __('Commonwealth of the Northern Mariana Islands', 'invoicing'),
531
+        'FM' => __('Federated States of Micronesia', 'invoicing'),
532
+        'GU' => __('Guam', 'invoicing'),
533
+        'MH' => __('Marshall Islands', 'invoicing'),
534
+        'MP' => __('Northern Mariana Islands', 'invoicing'),
535
+        'PW' => __('Palau', 'invoicing'),
536
+        'PI' => __('Philippine Islands', 'invoicing'),
537
+        'PR' => __('Puerto Rico', 'invoicing'),
538
+        'TT' => __('Trust Territory of the Pacific Islands', 'invoicing'),
539
+        'VI' => __('Virgin Islands', 'invoicing'),
540
+        'AA' => __('Armed Forces - Americas', 'invoicing'),
541
+        'AE' => __('Armed Forces - Europe, Canada, Middle East, Africa', 'invoicing'),
542
+        'AP' => __('Armed Forces - Pacific', 'invoicing')
543 543
     );
544 544
 
545
-    return apply_filters( 'wpinv_us_states', $states );
545
+    return apply_filters('wpinv_us_states', $states);
546 546
 }
547 547
 
548 548
 function wpinv_get_canada_states_list() {
549 549
     $states = array(
550
-        'AB' => __( 'Alberta', 'invoicing' ),
551
-        'BC' => __( 'British Columbia', 'invoicing' ),
552
-        'MB' => __( 'Manitoba', 'invoicing' ),
553
-        'NB' => __( 'New Brunswick', 'invoicing' ),
554
-        'NL' => __( 'Newfoundland and Labrador', 'invoicing' ),
555
-        'NS' => __( 'Nova Scotia', 'invoicing' ),
556
-        'NT' => __( 'Northwest Territories', 'invoicing' ),
557
-        'NU' => __( 'Nunavut', 'invoicing' ),
558
-        'ON' => __( 'Ontario', 'invoicing' ),
559
-        'PE' => __( 'Prince Edward Island', 'invoicing' ),
560
-        'QC' => __( 'Quebec', 'invoicing' ),
561
-        'SK' => __( 'Saskatchewan', 'invoicing' ),
562
-        'YT' => __( 'Yukon', 'invoicing' )
550
+        'AB' => __('Alberta', 'invoicing'),
551
+        'BC' => __('British Columbia', 'invoicing'),
552
+        'MB' => __('Manitoba', 'invoicing'),
553
+        'NB' => __('New Brunswick', 'invoicing'),
554
+        'NL' => __('Newfoundland and Labrador', 'invoicing'),
555
+        'NS' => __('Nova Scotia', 'invoicing'),
556
+        'NT' => __('Northwest Territories', 'invoicing'),
557
+        'NU' => __('Nunavut', 'invoicing'),
558
+        'ON' => __('Ontario', 'invoicing'),
559
+        'PE' => __('Prince Edward Island', 'invoicing'),
560
+        'QC' => __('Quebec', 'invoicing'),
561
+        'SK' => __('Saskatchewan', 'invoicing'),
562
+        'YT' => __('Yukon', 'invoicing')
563 563
     );
564 564
 
565
-    return apply_filters( 'wpinv_canada_provinces', $states );
565
+    return apply_filters('wpinv_canada_provinces', $states);
566 566
 }
567 567
 
568 568
 function wpinv_get_australia_states_list() {
569 569
     $states = array(
570
-        'ACT' => __( 'Australian Capital Territory', 'invoicing' ),
571
-        'NSW' => __( 'New South Wales', 'invoicing' ),
572
-        'NT'  => __( 'Northern Territory', 'invoicing' ),
573
-        'QLD' => __( 'Queensland', 'invoicing' ),
574
-        'SA'  => __( 'South Australia', 'invoicing' ),
575
-        'TAS' => __( 'Tasmania', 'invoicing' ),
576
-        'VIC' => __( 'Victoria', 'invoicing' ),
577
-        'WA'  => __( 'Western Australia', 'invoicing' )
570
+        'ACT' => __('Australian Capital Territory', 'invoicing'),
571
+        'NSW' => __('New South Wales', 'invoicing'),
572
+        'NT'  => __('Northern Territory', 'invoicing'),
573
+        'QLD' => __('Queensland', 'invoicing'),
574
+        'SA'  => __('South Australia', 'invoicing'),
575
+        'TAS' => __('Tasmania', 'invoicing'),
576
+        'VIC' => __('Victoria', 'invoicing'),
577
+        'WA'  => __('Western Australia', 'invoicing')
578 578
     );
579 579
 
580
-    return apply_filters( 'wpinv_australia_states', $states );
580
+    return apply_filters('wpinv_australia_states', $states);
581 581
 }
582 582
 
583 583
 function wpinv_get_bangladesh_states_list() {
584 584
     $states = array(
585
-        'BAG' => __( 'Bagerhat', 'invoicing' ),
586
-        'BAN' => __( 'Bandarban', 'invoicing' ),
587
-        'BAR' => __( 'Barguna', 'invoicing' ),
588
-        'BARI'=> __( 'Barisal', 'invoicing' ),
589
-        'BHO' => __( 'Bhola', 'invoicing' ),
590
-        'BOG' => __( 'Bogra', 'invoicing' ),
591
-        'BRA' => __( 'Brahmanbaria', 'invoicing' ),
592
-        'CHA' => __( 'Chandpur', 'invoicing' ),
593
-        'CHI' => __( 'Chittagong', 'invoicing' ),
594
-        'CHU' => __( 'Chuadanga', 'invoicing' ),
595
-        'COM' => __( 'Comilla', 'invoicing' ),
596
-        'COX' => __( 'Cox\'s Bazar', 'invoicing' ),
597
-        'DHA' => __( 'Dhaka', 'invoicing' ),
598
-        'DIN' => __( 'Dinajpur', 'invoicing' ),
599
-        'FAR' => __( 'Faridpur', 'invoicing' ),
600
-        'FEN' => __( 'Feni', 'invoicing' ),
601
-        'GAI' => __( 'Gaibandha', 'invoicing' ),
602
-        'GAZI'=> __( 'Gazipur', 'invoicing' ),
603
-        'GOP' => __( 'Gopalganj', 'invoicing' ),
604
-        'HAB' => __( 'Habiganj', 'invoicing' ),
605
-        'JAM' => __( 'Jamalpur', 'invoicing' ),
606
-        'JES' => __( 'Jessore', 'invoicing' ),
607
-        'JHA' => __( 'Jhalokati', 'invoicing' ),
608
-        'JHE' => __( 'Jhenaidah', 'invoicing' ),
609
-        'JOY' => __( 'Joypurhat', 'invoicing' ),
610
-        'KHA' => __( 'Khagrachhari', 'invoicing' ),
611
-        'KHU' => __( 'Khulna', 'invoicing' ),
612
-        'KIS' => __( 'Kishoreganj', 'invoicing' ),
613
-        'KUR' => __( 'Kurigram', 'invoicing' ),
614
-        'KUS' => __( 'Kushtia', 'invoicing' ),
615
-        'LAK' => __( 'Lakshmipur', 'invoicing' ),
616
-        'LAL' => __( 'Lalmonirhat', 'invoicing' ),
617
-        'MAD' => __( 'Madaripur', 'invoicing' ),
618
-        'MAG' => __( 'Magura', 'invoicing' ),
619
-        'MAN' => __( 'Manikganj', 'invoicing' ),
620
-        'MEH' => __( 'Meherpur', 'invoicing' ),
621
-        'MOU' => __( 'Moulvibazar', 'invoicing' ),
622
-        'MUN' => __( 'Munshiganj', 'invoicing' ),
623
-        'MYM' => __( 'Mymensingh', 'invoicing' ),
624
-        'NAO' => __( 'Naogaon', 'invoicing' ),
625
-        'NAR' => __( 'Narail', 'invoicing' ),
626
-        'NARG'=> __( 'Narayanganj', 'invoicing' ),
627
-        'NARD'=> __( 'Narsingdi', 'invoicing' ),
628
-        'NAT' => __( 'Natore', 'invoicing' ),
629
-        'NAW' => __( 'Nawabganj', 'invoicing' ),
630
-        'NET' => __( 'Netrakona', 'invoicing' ),
631
-        'NIL' => __( 'Nilphamari', 'invoicing' ),
632
-        'NOA' => __( 'Noakhali', 'invoicing' ),
633
-        'PAB' => __( 'Pabna', 'invoicing' ),
634
-        'PAN' => __( 'Panchagarh', 'invoicing' ),
635
-        'PAT' => __( 'Patuakhali', 'invoicing' ),
636
-        'PIR' => __( 'Pirojpur', 'invoicing' ),
637
-        'RAJB'=> __( 'Rajbari', 'invoicing' ),
638
-        'RAJ' => __( 'Rajshahi', 'invoicing' ),
639
-        'RAN' => __( 'Rangamati', 'invoicing' ),
640
-        'RANP'=> __( 'Rangpur', 'invoicing' ),
641
-        'SAT' => __( 'Satkhira', 'invoicing' ),
642
-        'SHA' => __( 'Shariatpur', 'invoicing' ),
643
-        'SHE' => __( 'Sherpur', 'invoicing' ),
644
-        'SIR' => __( 'Sirajganj', 'invoicing' ),
645
-        'SUN' => __( 'Sunamganj', 'invoicing' ),
646
-        'SYL' => __( 'Sylhet', 'invoicing' ),
647
-        'TAN' => __( 'Tangail', 'invoicing' ),
648
-        'THA' => __( 'Thakurgaon', 'invoicing' )
585
+        'BAG' => __('Bagerhat', 'invoicing'),
586
+        'BAN' => __('Bandarban', 'invoicing'),
587
+        'BAR' => __('Barguna', 'invoicing'),
588
+        'BARI'=> __('Barisal', 'invoicing'),
589
+        'BHO' => __('Bhola', 'invoicing'),
590
+        'BOG' => __('Bogra', 'invoicing'),
591
+        'BRA' => __('Brahmanbaria', 'invoicing'),
592
+        'CHA' => __('Chandpur', 'invoicing'),
593
+        'CHI' => __('Chittagong', 'invoicing'),
594
+        'CHU' => __('Chuadanga', 'invoicing'),
595
+        'COM' => __('Comilla', 'invoicing'),
596
+        'COX' => __('Cox\'s Bazar', 'invoicing'),
597
+        'DHA' => __('Dhaka', 'invoicing'),
598
+        'DIN' => __('Dinajpur', 'invoicing'),
599
+        'FAR' => __('Faridpur', 'invoicing'),
600
+        'FEN' => __('Feni', 'invoicing'),
601
+        'GAI' => __('Gaibandha', 'invoicing'),
602
+        'GAZI'=> __('Gazipur', 'invoicing'),
603
+        'GOP' => __('Gopalganj', 'invoicing'),
604
+        'HAB' => __('Habiganj', 'invoicing'),
605
+        'JAM' => __('Jamalpur', 'invoicing'),
606
+        'JES' => __('Jessore', 'invoicing'),
607
+        'JHA' => __('Jhalokati', 'invoicing'),
608
+        'JHE' => __('Jhenaidah', 'invoicing'),
609
+        'JOY' => __('Joypurhat', 'invoicing'),
610
+        'KHA' => __('Khagrachhari', 'invoicing'),
611
+        'KHU' => __('Khulna', 'invoicing'),
612
+        'KIS' => __('Kishoreganj', 'invoicing'),
613
+        'KUR' => __('Kurigram', 'invoicing'),
614
+        'KUS' => __('Kushtia', 'invoicing'),
615
+        'LAK' => __('Lakshmipur', 'invoicing'),
616
+        'LAL' => __('Lalmonirhat', 'invoicing'),
617
+        'MAD' => __('Madaripur', 'invoicing'),
618
+        'MAG' => __('Magura', 'invoicing'),
619
+        'MAN' => __('Manikganj', 'invoicing'),
620
+        'MEH' => __('Meherpur', 'invoicing'),
621
+        'MOU' => __('Moulvibazar', 'invoicing'),
622
+        'MUN' => __('Munshiganj', 'invoicing'),
623
+        'MYM' => __('Mymensingh', 'invoicing'),
624
+        'NAO' => __('Naogaon', 'invoicing'),
625
+        'NAR' => __('Narail', 'invoicing'),
626
+        'NARG'=> __('Narayanganj', 'invoicing'),
627
+        'NARD'=> __('Narsingdi', 'invoicing'),
628
+        'NAT' => __('Natore', 'invoicing'),
629
+        'NAW' => __('Nawabganj', 'invoicing'),
630
+        'NET' => __('Netrakona', 'invoicing'),
631
+        'NIL' => __('Nilphamari', 'invoicing'),
632
+        'NOA' => __('Noakhali', 'invoicing'),
633
+        'PAB' => __('Pabna', 'invoicing'),
634
+        'PAN' => __('Panchagarh', 'invoicing'),
635
+        'PAT' => __('Patuakhali', 'invoicing'),
636
+        'PIR' => __('Pirojpur', 'invoicing'),
637
+        'RAJB'=> __('Rajbari', 'invoicing'),
638
+        'RAJ' => __('Rajshahi', 'invoicing'),
639
+        'RAN' => __('Rangamati', 'invoicing'),
640
+        'RANP'=> __('Rangpur', 'invoicing'),
641
+        'SAT' => __('Satkhira', 'invoicing'),
642
+        'SHA' => __('Shariatpur', 'invoicing'),
643
+        'SHE' => __('Sherpur', 'invoicing'),
644
+        'SIR' => __('Sirajganj', 'invoicing'),
645
+        'SUN' => __('Sunamganj', 'invoicing'),
646
+        'SYL' => __('Sylhet', 'invoicing'),
647
+        'TAN' => __('Tangail', 'invoicing'),
648
+        'THA' => __('Thakurgaon', 'invoicing')
649 649
     );
650 650
 
651
-    return apply_filters( 'wpinv_bangladesh_states', $states );
651
+    return apply_filters('wpinv_bangladesh_states', $states);
652 652
 }
653 653
 
654 654
 function wpinv_get_brazil_states_list() {
655 655
     $states = array(
656
-        'AC' => __( 'Acre', 'invoicing' ),
657
-        'AL' => __( 'Alagoas', 'invoicing' ),
658
-        'AP' => __( 'Amap&aacute;', 'invoicing' ),
659
-        'AM' => __( 'Amazonas', 'invoicing' ),
660
-        'BA' => __( 'Bahia', 'invoicing' ),
661
-        'CE' => __( 'Cear&aacute;', 'invoicing' ),
662
-        'DF' => __( 'Distrito Federal', 'invoicing' ),
663
-        'ES' => __( 'Esp&iacute;rito Santo', 'invoicing' ),
664
-        'GO' => __( 'Goi&aacute;s', 'invoicing' ),
665
-        'MA' => __( 'Maranh&atilde;o', 'invoicing' ),
666
-        'MT' => __( 'Mato Grosso', 'invoicing' ),
667
-        'MS' => __( 'Mato Grosso do Sul', 'invoicing' ),
668
-        'MG' => __( 'Minas Gerais', 'invoicing' ),
669
-        'PA' => __( 'Par&aacute;', 'invoicing' ),
670
-        'PB' => __( 'Para&iacute;ba', 'invoicing' ),
671
-        'PR' => __( 'Paran&aacute;', 'invoicing' ),
672
-        'PE' => __( 'Pernambuco', 'invoicing' ),
673
-        'PI' => __( 'Piau&iacute;', 'invoicing' ),
674
-        'RJ' => __( 'Rio de Janeiro', 'invoicing' ),
675
-        'RN' => __( 'Rio Grande do Norte', 'invoicing' ),
676
-        'RS' => __( 'Rio Grande do Sul', 'invoicing' ),
677
-        'RO' => __( 'Rond&ocirc;nia', 'invoicing' ),
678
-        'RR' => __( 'Roraima', 'invoicing' ),
679
-        'SC' => __( 'Santa Catarina', 'invoicing' ),
680
-        'SP' => __( 'S&atilde;o Paulo', 'invoicing' ),
681
-        'SE' => __( 'Sergipe', 'invoicing' ),
682
-        'TO' => __( 'Tocantins', 'invoicing' )
656
+        'AC' => __('Acre', 'invoicing'),
657
+        'AL' => __('Alagoas', 'invoicing'),
658
+        'AP' => __('Amap&aacute;', 'invoicing'),
659
+        'AM' => __('Amazonas', 'invoicing'),
660
+        'BA' => __('Bahia', 'invoicing'),
661
+        'CE' => __('Cear&aacute;', 'invoicing'),
662
+        'DF' => __('Distrito Federal', 'invoicing'),
663
+        'ES' => __('Esp&iacute;rito Santo', 'invoicing'),
664
+        'GO' => __('Goi&aacute;s', 'invoicing'),
665
+        'MA' => __('Maranh&atilde;o', 'invoicing'),
666
+        'MT' => __('Mato Grosso', 'invoicing'),
667
+        'MS' => __('Mato Grosso do Sul', 'invoicing'),
668
+        'MG' => __('Minas Gerais', 'invoicing'),
669
+        'PA' => __('Par&aacute;', 'invoicing'),
670
+        'PB' => __('Para&iacute;ba', 'invoicing'),
671
+        'PR' => __('Paran&aacute;', 'invoicing'),
672
+        'PE' => __('Pernambuco', 'invoicing'),
673
+        'PI' => __('Piau&iacute;', 'invoicing'),
674
+        'RJ' => __('Rio de Janeiro', 'invoicing'),
675
+        'RN' => __('Rio Grande do Norte', 'invoicing'),
676
+        'RS' => __('Rio Grande do Sul', 'invoicing'),
677
+        'RO' => __('Rond&ocirc;nia', 'invoicing'),
678
+        'RR' => __('Roraima', 'invoicing'),
679
+        'SC' => __('Santa Catarina', 'invoicing'),
680
+        'SP' => __('S&atilde;o Paulo', 'invoicing'),
681
+        'SE' => __('Sergipe', 'invoicing'),
682
+        'TO' => __('Tocantins', 'invoicing')
683 683
     );
684 684
 
685
-    return apply_filters( 'wpinv_brazil_states', $states );
685
+    return apply_filters('wpinv_brazil_states', $states);
686 686
 }
687 687
 
688 688
 function wpinv_get_bulgaria_states_list() {
689 689
     $states = array(
690
-        'BG-01' => __( 'Blagoevgrad', 'invoicing' ),
691
-        'BG-02' => __( 'Burgas', 'invoicing' ),
692
-        'BG-08' => __( 'Dobrich', 'invoicing' ),
693
-        'BG-07' => __( 'Gabrovo', 'invoicing' ),
694
-        'BG-26' => __( 'Haskovo', 'invoicing' ),
695
-        'BG-09' => __( 'Kardzhali', 'invoicing' ),
696
-        'BG-10' => __( 'Kyustendil', 'invoicing' ),
697
-        'BG-11' => __( 'Lovech', 'invoicing' ),
698
-        'BG-12' => __( 'Montana', 'invoicing' ),
699
-        'BG-13' => __( 'Pazardzhik', 'invoicing' ),
700
-        'BG-14' => __( 'Pernik', 'invoicing' ),
701
-        'BG-15' => __( 'Pleven', 'invoicing' ),
702
-        'BG-16' => __( 'Plovdiv', 'invoicing' ),
703
-        'BG-17' => __( 'Razgrad', 'invoicing' ),
704
-        'BG-18' => __( 'Ruse', 'invoicing' ),
705
-        'BG-27' => __( 'Shumen', 'invoicing' ),
706
-        'BG-19' => __( 'Silistra', 'invoicing' ),
707
-        'BG-20' => __( 'Sliven', 'invoicing' ),
708
-        'BG-21' => __( 'Smolyan', 'invoicing' ),
709
-        'BG-23' => __( 'Sofia', 'invoicing' ),
710
-        'BG-22' => __( 'Sofia-Grad', 'invoicing' ),
711
-        'BG-24' => __( 'Stara Zagora', 'invoicing' ),
712
-        'BG-25' => __( 'Targovishte', 'invoicing' ),
713
-        'BG-03' => __( 'Varna', 'invoicing' ),
714
-        'BG-04' => __( 'Veliko Tarnovo', 'invoicing' ),
715
-        'BG-05' => __( 'Vidin', 'invoicing' ),
716
-        'BG-06' => __( 'Vratsa', 'invoicing' ),
717
-        'BG-28' => __( 'Yambol', 'invoicing' )
690
+        'BG-01' => __('Blagoevgrad', 'invoicing'),
691
+        'BG-02' => __('Burgas', 'invoicing'),
692
+        'BG-08' => __('Dobrich', 'invoicing'),
693
+        'BG-07' => __('Gabrovo', 'invoicing'),
694
+        'BG-26' => __('Haskovo', 'invoicing'),
695
+        'BG-09' => __('Kardzhali', 'invoicing'),
696
+        'BG-10' => __('Kyustendil', 'invoicing'),
697
+        'BG-11' => __('Lovech', 'invoicing'),
698
+        'BG-12' => __('Montana', 'invoicing'),
699
+        'BG-13' => __('Pazardzhik', 'invoicing'),
700
+        'BG-14' => __('Pernik', 'invoicing'),
701
+        'BG-15' => __('Pleven', 'invoicing'),
702
+        'BG-16' => __('Plovdiv', 'invoicing'),
703
+        'BG-17' => __('Razgrad', 'invoicing'),
704
+        'BG-18' => __('Ruse', 'invoicing'),
705
+        'BG-27' => __('Shumen', 'invoicing'),
706
+        'BG-19' => __('Silistra', 'invoicing'),
707
+        'BG-20' => __('Sliven', 'invoicing'),
708
+        'BG-21' => __('Smolyan', 'invoicing'),
709
+        'BG-23' => __('Sofia', 'invoicing'),
710
+        'BG-22' => __('Sofia-Grad', 'invoicing'),
711
+        'BG-24' => __('Stara Zagora', 'invoicing'),
712
+        'BG-25' => __('Targovishte', 'invoicing'),
713
+        'BG-03' => __('Varna', 'invoicing'),
714
+        'BG-04' => __('Veliko Tarnovo', 'invoicing'),
715
+        'BG-05' => __('Vidin', 'invoicing'),
716
+        'BG-06' => __('Vratsa', 'invoicing'),
717
+        'BG-28' => __('Yambol', 'invoicing')
718 718
     );
719 719
 
720
-    return apply_filters( 'wpinv_bulgaria_states', $states );
720
+    return apply_filters('wpinv_bulgaria_states', $states);
721 721
 }
722 722
 
723 723
 function wpinv_get_hong_kong_states_list() {
724 724
     $states = array(
725
-        'HONG KONG'       => __( 'Hong Kong Island', 'invoicing' ),
726
-        'KOWLOON'         => __( 'Kowloon', 'invoicing' ),
727
-        'NEW TERRITORIES' => __( 'New Territories', 'invoicing' )
725
+        'HONG KONG'       => __('Hong Kong Island', 'invoicing'),
726
+        'KOWLOON'         => __('Kowloon', 'invoicing'),
727
+        'NEW TERRITORIES' => __('New Territories', 'invoicing')
728 728
     );
729 729
 
730
-    return apply_filters( 'wpinv_hong_kong_states', $states );
730
+    return apply_filters('wpinv_hong_kong_states', $states);
731 731
 }
732 732
 
733 733
 function wpinv_get_hungary_states_list() {
734 734
     $states = array(
735
-        'BK' => __( 'Bács-Kiskun', 'invoicing' ),
736
-        'BE' => __( 'Békés', 'invoicing' ),
737
-        'BA' => __( 'Baranya', 'invoicing' ),
738
-        'BZ' => __( 'Borsod-Abaúj-Zemplén', 'invoicing' ),
739
-        'BU' => __( 'Budapest', 'invoicing' ),
740
-        'CS' => __( 'Csongrád', 'invoicing' ),
741
-        'FE' => __( 'Fejér', 'invoicing' ),
742
-        'GS' => __( 'Győr-Moson-Sopron', 'invoicing' ),
743
-        'HB' => __( 'Hajdú-Bihar', 'invoicing' ),
744
-        'HE' => __( 'Heves', 'invoicing' ),
745
-        'JN' => __( 'Jász-Nagykun-Szolnok', 'invoicing' ),
746
-        'KE' => __( 'Komárom-Esztergom', 'invoicing' ),
747
-        'NO' => __( 'Nógrád', 'invoicing' ),
748
-        'PE' => __( 'Pest', 'invoicing' ),
749
-        'SO' => __( 'Somogy', 'invoicing' ),
750
-        'SZ' => __( 'Szabolcs-Szatmár-Bereg', 'invoicing' ),
751
-        'TO' => __( 'Tolna', 'invoicing' ),
752
-        'VA' => __( 'Vas', 'invoicing' ),
753
-        'VE' => __( 'Veszprém', 'invoicing' ),
754
-        'ZA' => __( 'Zala', 'invoicing' )
735
+        'BK' => __('Bács-Kiskun', 'invoicing'),
736
+        'BE' => __('Békés', 'invoicing'),
737
+        'BA' => __('Baranya', 'invoicing'),
738
+        'BZ' => __('Borsod-Abaúj-Zemplén', 'invoicing'),
739
+        'BU' => __('Budapest', 'invoicing'),
740
+        'CS' => __('Csongrád', 'invoicing'),
741
+        'FE' => __('Fejér', 'invoicing'),
742
+        'GS' => __('Győr-Moson-Sopron', 'invoicing'),
743
+        'HB' => __('Hajdú-Bihar', 'invoicing'),
744
+        'HE' => __('Heves', 'invoicing'),
745
+        'JN' => __('Jász-Nagykun-Szolnok', 'invoicing'),
746
+        'KE' => __('Komárom-Esztergom', 'invoicing'),
747
+        'NO' => __('Nógrád', 'invoicing'),
748
+        'PE' => __('Pest', 'invoicing'),
749
+        'SO' => __('Somogy', 'invoicing'),
750
+        'SZ' => __('Szabolcs-Szatmár-Bereg', 'invoicing'),
751
+        'TO' => __('Tolna', 'invoicing'),
752
+        'VA' => __('Vas', 'invoicing'),
753
+        'VE' => __('Veszprém', 'invoicing'),
754
+        'ZA' => __('Zala', 'invoicing')
755 755
     );
756 756
 
757
-    return apply_filters( 'wpinv_hungary_states', $states );
757
+    return apply_filters('wpinv_hungary_states', $states);
758 758
 }
759 759
 
760 760
 function wpinv_get_japan_states_list() {
761 761
     $states = array(
762
-        'JP01' => __( 'Hokkaido', 'invoicing' ),
763
-        'JP02' => __( 'Aomori', 'invoicing' ),
764
-        'JP03' => __( 'Iwate', 'invoicing' ),
765
-        'JP04' => __( 'Miyagi', 'invoicing' ),
766
-        'JP05' => __( 'Akita', 'invoicing' ),
767
-        'JP06' => __( 'Yamagata', 'invoicing' ),
768
-        'JP07' => __( 'Fukushima', 'invoicing' ),
769
-        'JP08' => __( 'Ibaraki', 'invoicing' ),
770
-        'JP09' => __( 'Tochigi', 'invoicing' ),
771
-        'JP10' => __( 'Gunma', 'invoicing' ),
772
-        'JP11' => __( 'Saitama', 'invoicing' ),
773
-        'JP12' => __( 'Chiba', 'invoicing' ),
774
-        'JP13' => __( 'Tokyo', 'invoicing' ),
775
-        'JP14' => __( 'Kanagawa', 'invoicing' ),
776
-        'JP15' => __( 'Niigata', 'invoicing' ),
777
-        'JP16' => __( 'Toyama', 'invoicing' ),
778
-        'JP17' => __( 'Ishikawa', 'invoicing' ),
779
-        'JP18' => __( 'Fukui', 'invoicing' ),
780
-        'JP19' => __( 'Yamanashi', 'invoicing' ),
781
-        'JP20' => __( 'Nagano', 'invoicing' ),
782
-        'JP21' => __( 'Gifu', 'invoicing' ),
783
-        'JP22' => __( 'Shizuoka', 'invoicing' ),
784
-        'JP23' => __( 'Aichi', 'invoicing' ),
785
-        'JP24' => __( 'Mie', 'invoicing' ),
786
-        'JP25' => __( 'Shiga', 'invoicing' ),
787
-        'JP26' => __( 'Kyouto', 'invoicing' ),
788
-        'JP27' => __( 'Osaka', 'invoicing' ),
789
-        'JP28' => __( 'Hyougo', 'invoicing' ),
790
-        'JP29' => __( 'Nara', 'invoicing' ),
791
-        'JP30' => __( 'Wakayama', 'invoicing' ),
792
-        'JP31' => __( 'Tottori', 'invoicing' ),
793
-        'JP32' => __( 'Shimane', 'invoicing' ),
794
-        'JP33' => __( 'Okayama', 'invoicing' ),
795
-        'JP34' => __( 'Hiroshima', 'invoicing' ),
796
-        'JP35' => __( 'Yamaguchi', 'invoicing' ),
797
-        'JP36' => __( 'Tokushima', 'invoicing' ),
798
-        'JP37' => __( 'Kagawa', 'invoicing' ),
799
-        'JP38' => __( 'Ehime', 'invoicing' ),
800
-        'JP39' => __( 'Kochi', 'invoicing' ),
801
-        'JP40' => __( 'Fukuoka', 'invoicing' ),
802
-        'JP41' => __( 'Saga', 'invoicing' ),
803
-        'JP42' => __( 'Nagasaki', 'invoicing' ),
804
-        'JP43' => __( 'Kumamoto', 'invoicing' ),
805
-        'JP44' => __( 'Oita', 'invoicing' ),
806
-        'JP45' => __( 'Miyazaki', 'invoicing' ),
807
-        'JP46' => __( 'Kagoshima', 'invoicing' ),
808
-        'JP47' => __( 'Okinawa', 'invoicing' )
762
+        'JP01' => __('Hokkaido', 'invoicing'),
763
+        'JP02' => __('Aomori', 'invoicing'),
764
+        'JP03' => __('Iwate', 'invoicing'),
765
+        'JP04' => __('Miyagi', 'invoicing'),
766
+        'JP05' => __('Akita', 'invoicing'),
767
+        'JP06' => __('Yamagata', 'invoicing'),
768
+        'JP07' => __('Fukushima', 'invoicing'),
769
+        'JP08' => __('Ibaraki', 'invoicing'),
770
+        'JP09' => __('Tochigi', 'invoicing'),
771
+        'JP10' => __('Gunma', 'invoicing'),
772
+        'JP11' => __('Saitama', 'invoicing'),
773
+        'JP12' => __('Chiba', 'invoicing'),
774
+        'JP13' => __('Tokyo', 'invoicing'),
775
+        'JP14' => __('Kanagawa', 'invoicing'),
776
+        'JP15' => __('Niigata', 'invoicing'),
777
+        'JP16' => __('Toyama', 'invoicing'),
778
+        'JP17' => __('Ishikawa', 'invoicing'),
779
+        'JP18' => __('Fukui', 'invoicing'),
780
+        'JP19' => __('Yamanashi', 'invoicing'),
781
+        'JP20' => __('Nagano', 'invoicing'),
782
+        'JP21' => __('Gifu', 'invoicing'),
783
+        'JP22' => __('Shizuoka', 'invoicing'),
784
+        'JP23' => __('Aichi', 'invoicing'),
785
+        'JP24' => __('Mie', 'invoicing'),
786
+        'JP25' => __('Shiga', 'invoicing'),
787
+        'JP26' => __('Kyouto', 'invoicing'),
788
+        'JP27' => __('Osaka', 'invoicing'),
789
+        'JP28' => __('Hyougo', 'invoicing'),
790
+        'JP29' => __('Nara', 'invoicing'),
791
+        'JP30' => __('Wakayama', 'invoicing'),
792
+        'JP31' => __('Tottori', 'invoicing'),
793
+        'JP32' => __('Shimane', 'invoicing'),
794
+        'JP33' => __('Okayama', 'invoicing'),
795
+        'JP34' => __('Hiroshima', 'invoicing'),
796
+        'JP35' => __('Yamaguchi', 'invoicing'),
797
+        'JP36' => __('Tokushima', 'invoicing'),
798
+        'JP37' => __('Kagawa', 'invoicing'),
799
+        'JP38' => __('Ehime', 'invoicing'),
800
+        'JP39' => __('Kochi', 'invoicing'),
801
+        'JP40' => __('Fukuoka', 'invoicing'),
802
+        'JP41' => __('Saga', 'invoicing'),
803
+        'JP42' => __('Nagasaki', 'invoicing'),
804
+        'JP43' => __('Kumamoto', 'invoicing'),
805
+        'JP44' => __('Oita', 'invoicing'),
806
+        'JP45' => __('Miyazaki', 'invoicing'),
807
+        'JP46' => __('Kagoshima', 'invoicing'),
808
+        'JP47' => __('Okinawa', 'invoicing')
809 809
     );
810 810
 
811
-    return apply_filters( 'wpinv_japan_states', $states );
811
+    return apply_filters('wpinv_japan_states', $states);
812 812
 }
813 813
 
814 814
 function wpinv_get_china_states_list() {
815 815
     $states = array(
816
-        'CN1'  => __( 'Yunnan / &#20113;&#21335;', 'invoicing' ),
817
-        'CN2'  => __( 'Beijing / &#21271;&#20140;', 'invoicing' ),
818
-        'CN3'  => __( 'Tianjin / &#22825;&#27941;', 'invoicing' ),
819
-        'CN4'  => __( 'Hebei / &#27827;&#21271;', 'invoicing' ),
820
-        'CN5'  => __( 'Shanxi / &#23665;&#35199;', 'invoicing' ),
821
-        'CN6'  => __( 'Inner Mongolia / &#20839;&#33945;&#21476;', 'invoicing' ),
822
-        'CN7'  => __( 'Liaoning / &#36797;&#23425;', 'invoicing' ),
823
-        'CN8'  => __( 'Jilin / &#21513;&#26519;', 'invoicing' ),
824
-        'CN9'  => __( 'Heilongjiang / &#40657;&#40857;&#27743;', 'invoicing' ),
825
-        'CN10' => __( 'Shanghai / &#19978;&#28023;', 'invoicing' ),
826
-        'CN11' => __( 'Jiangsu / &#27743;&#33487;', 'invoicing' ),
827
-        'CN12' => __( 'Zhejiang / &#27993;&#27743;', 'invoicing' ),
828
-        'CN13' => __( 'Anhui / &#23433;&#24509;', 'invoicing' ),
829
-        'CN14' => __( 'Fujian / &#31119;&#24314;', 'invoicing' ),
830
-        'CN15' => __( 'Jiangxi / &#27743;&#35199;', 'invoicing' ),
831
-        'CN16' => __( 'Shandong / &#23665;&#19996;', 'invoicing' ),
832
-        'CN17' => __( 'Henan / &#27827;&#21335;', 'invoicing' ),
833
-        'CN18' => __( 'Hubei / &#28246;&#21271;', 'invoicing' ),
834
-        'CN19' => __( 'Hunan / &#28246;&#21335;', 'invoicing' ),
835
-        'CN20' => __( 'Guangdong / &#24191;&#19996;', 'invoicing' ),
836
-        'CN21' => __( 'Guangxi Zhuang / &#24191;&#35199;&#22766;&#26063;', 'invoicing' ),
837
-        'CN22' => __( 'Hainan / &#28023;&#21335;', 'invoicing' ),
838
-        'CN23' => __( 'Chongqing / &#37325;&#24198;', 'invoicing' ),
839
-        'CN24' => __( 'Sichuan / &#22235;&#24029;', 'invoicing' ),
840
-        'CN25' => __( 'Guizhou / &#36149;&#24030;', 'invoicing' ),
841
-        'CN26' => __( 'Shaanxi / &#38485;&#35199;', 'invoicing' ),
842
-        'CN27' => __( 'Gansu / &#29976;&#32899;', 'invoicing' ),
843
-        'CN28' => __( 'Qinghai / &#38738;&#28023;', 'invoicing' ),
844
-        'CN29' => __( 'Ningxia Hui / &#23425;&#22799;', 'invoicing' ),
845
-        'CN30' => __( 'Macau / &#28595;&#38376;', 'invoicing' ),
846
-        'CN31' => __( 'Tibet / &#35199;&#34255;', 'invoicing' ),
847
-        'CN32' => __( 'Xinjiang / &#26032;&#30086;', 'invoicing' )
816
+        'CN1'  => __('Yunnan / &#20113;&#21335;', 'invoicing'),
817
+        'CN2'  => __('Beijing / &#21271;&#20140;', 'invoicing'),
818
+        'CN3'  => __('Tianjin / &#22825;&#27941;', 'invoicing'),
819
+        'CN4'  => __('Hebei / &#27827;&#21271;', 'invoicing'),
820
+        'CN5'  => __('Shanxi / &#23665;&#35199;', 'invoicing'),
821
+        'CN6'  => __('Inner Mongolia / &#20839;&#33945;&#21476;', 'invoicing'),
822
+        'CN7'  => __('Liaoning / &#36797;&#23425;', 'invoicing'),
823
+        'CN8'  => __('Jilin / &#21513;&#26519;', 'invoicing'),
824
+        'CN9'  => __('Heilongjiang / &#40657;&#40857;&#27743;', 'invoicing'),
825
+        'CN10' => __('Shanghai / &#19978;&#28023;', 'invoicing'),
826
+        'CN11' => __('Jiangsu / &#27743;&#33487;', 'invoicing'),
827
+        'CN12' => __('Zhejiang / &#27993;&#27743;', 'invoicing'),
828
+        'CN13' => __('Anhui / &#23433;&#24509;', 'invoicing'),
829
+        'CN14' => __('Fujian / &#31119;&#24314;', 'invoicing'),
830
+        'CN15' => __('Jiangxi / &#27743;&#35199;', 'invoicing'),
831
+        'CN16' => __('Shandong / &#23665;&#19996;', 'invoicing'),
832
+        'CN17' => __('Henan / &#27827;&#21335;', 'invoicing'),
833
+        'CN18' => __('Hubei / &#28246;&#21271;', 'invoicing'),
834
+        'CN19' => __('Hunan / &#28246;&#21335;', 'invoicing'),
835
+        'CN20' => __('Guangdong / &#24191;&#19996;', 'invoicing'),
836
+        'CN21' => __('Guangxi Zhuang / &#24191;&#35199;&#22766;&#26063;', 'invoicing'),
837
+        'CN22' => __('Hainan / &#28023;&#21335;', 'invoicing'),
838
+        'CN23' => __('Chongqing / &#37325;&#24198;', 'invoicing'),
839
+        'CN24' => __('Sichuan / &#22235;&#24029;', 'invoicing'),
840
+        'CN25' => __('Guizhou / &#36149;&#24030;', 'invoicing'),
841
+        'CN26' => __('Shaanxi / &#38485;&#35199;', 'invoicing'),
842
+        'CN27' => __('Gansu / &#29976;&#32899;', 'invoicing'),
843
+        'CN28' => __('Qinghai / &#38738;&#28023;', 'invoicing'),
844
+        'CN29' => __('Ningxia Hui / &#23425;&#22799;', 'invoicing'),
845
+        'CN30' => __('Macau / &#28595;&#38376;', 'invoicing'),
846
+        'CN31' => __('Tibet / &#35199;&#34255;', 'invoicing'),
847
+        'CN32' => __('Xinjiang / &#26032;&#30086;', 'invoicing')
848 848
     );
849 849
 
850
-    return apply_filters( 'wpinv_china_states', $states );
850
+    return apply_filters('wpinv_china_states', $states);
851 851
 }
852 852
 
853 853
 function wpinv_get_new_zealand_states_list() {
854 854
     $states = array(
855
-        'AK' => __( 'Auckland', 'invoicing' ),
856
-        'BP' => __( 'Bay of Plenty', 'invoicing' ),
857
-        'CT' => __( 'Canterbury', 'invoicing' ),
858
-        'HB' => __( 'Hawke&rsquo;s Bay', 'invoicing' ),
859
-        'MW' => __( 'Manawatu-Wanganui', 'invoicing' ),
860
-        'MB' => __( 'Marlborough', 'invoicing' ),
861
-        'NS' => __( 'Nelson', 'invoicing' ),
862
-        'NL' => __( 'Northland', 'invoicing' ),
863
-        'OT' => __( 'Otago', 'invoicing' ),
864
-        'SL' => __( 'Southland', 'invoicing' ),
865
-        'TK' => __( 'Taranaki', 'invoicing' ),
866
-        'TM' => __( 'Tasman', 'invoicing' ),
867
-        'WA' => __( 'Waikato', 'invoicing' ),
868
-        'WR' => __( 'Wairarapa', 'invoicing' ),
869
-        'WE' => __( 'Wellington', 'invoicing' ),
870
-        'WC' => __( 'West Coast', 'invoicing' )
855
+        'AK' => __('Auckland', 'invoicing'),
856
+        'BP' => __('Bay of Plenty', 'invoicing'),
857
+        'CT' => __('Canterbury', 'invoicing'),
858
+        'HB' => __('Hawke&rsquo;s Bay', 'invoicing'),
859
+        'MW' => __('Manawatu-Wanganui', 'invoicing'),
860
+        'MB' => __('Marlborough', 'invoicing'),
861
+        'NS' => __('Nelson', 'invoicing'),
862
+        'NL' => __('Northland', 'invoicing'),
863
+        'OT' => __('Otago', 'invoicing'),
864
+        'SL' => __('Southland', 'invoicing'),
865
+        'TK' => __('Taranaki', 'invoicing'),
866
+        'TM' => __('Tasman', 'invoicing'),
867
+        'WA' => __('Waikato', 'invoicing'),
868
+        'WR' => __('Wairarapa', 'invoicing'),
869
+        'WE' => __('Wellington', 'invoicing'),
870
+        'WC' => __('West Coast', 'invoicing')
871 871
     );
872 872
 
873
-    return apply_filters( 'wpinv_new_zealand_states', $states );
873
+    return apply_filters('wpinv_new_zealand_states', $states);
874 874
 }
875 875
 
876 876
 function wpinv_get_peru_states_list() {
877 877
     $states = array(
878
-        'CAL' => __( 'El Callao', 'invoicing' ),
879
-        'LMA' => __( 'Municipalidad Metropolitana de Lima', 'invoicing' ),
880
-        'AMA' => __( 'Amazonas', 'invoicing' ),
881
-        'ANC' => __( 'Ancash', 'invoicing' ),
882
-        'APU' => __( 'Apur&iacute;mac', 'invoicing' ),
883
-        'ARE' => __( 'Arequipa', 'invoicing' ),
884
-        'AYA' => __( 'Ayacucho', 'invoicing' ),
885
-        'CAJ' => __( 'Cajamarca', 'invoicing' ),
886
-        'CUS' => __( 'Cusco', 'invoicing' ),
887
-        'HUV' => __( 'Huancavelica', 'invoicing' ),
888
-        'HUC' => __( 'Hu&aacute;nuco', 'invoicing' ),
889
-        'ICA' => __( 'Ica', 'invoicing' ),
890
-        'JUN' => __( 'Jun&iacute;n', 'invoicing' ),
891
-        'LAL' => __( 'La Libertad', 'invoicing' ),
892
-        'LAM' => __( 'Lambayeque', 'invoicing' ),
893
-        'LIM' => __( 'Lima', 'invoicing' ),
894
-        'LOR' => __( 'Loreto', 'invoicing' ),
895
-        'MDD' => __( 'Madre de Dios', 'invoicing' ),
896
-        'MOQ' => __( 'Moquegua', 'invoicing' ),
897
-        'PAS' => __( 'Pasco', 'invoicing' ),
898
-        'PIU' => __( 'Piura', 'invoicing' ),
899
-        'PUN' => __( 'Puno', 'invoicing' ),
900
-        'SAM' => __( 'San Mart&iacute;n', 'invoicing' ),
901
-        'TAC' => __( 'Tacna', 'invoicing' ),
902
-        'TUM' => __( 'Tumbes', 'invoicing' ),
903
-        'UCA' => __( 'Ucayali', 'invoicing' )
878
+        'CAL' => __('El Callao', 'invoicing'),
879
+        'LMA' => __('Municipalidad Metropolitana de Lima', 'invoicing'),
880
+        'AMA' => __('Amazonas', 'invoicing'),
881
+        'ANC' => __('Ancash', 'invoicing'),
882
+        'APU' => __('Apur&iacute;mac', 'invoicing'),
883
+        'ARE' => __('Arequipa', 'invoicing'),
884
+        'AYA' => __('Ayacucho', 'invoicing'),
885
+        'CAJ' => __('Cajamarca', 'invoicing'),
886
+        'CUS' => __('Cusco', 'invoicing'),
887
+        'HUV' => __('Huancavelica', 'invoicing'),
888
+        'HUC' => __('Hu&aacute;nuco', 'invoicing'),
889
+        'ICA' => __('Ica', 'invoicing'),
890
+        'JUN' => __('Jun&iacute;n', 'invoicing'),
891
+        'LAL' => __('La Libertad', 'invoicing'),
892
+        'LAM' => __('Lambayeque', 'invoicing'),
893
+        'LIM' => __('Lima', 'invoicing'),
894
+        'LOR' => __('Loreto', 'invoicing'),
895
+        'MDD' => __('Madre de Dios', 'invoicing'),
896
+        'MOQ' => __('Moquegua', 'invoicing'),
897
+        'PAS' => __('Pasco', 'invoicing'),
898
+        'PIU' => __('Piura', 'invoicing'),
899
+        'PUN' => __('Puno', 'invoicing'),
900
+        'SAM' => __('San Mart&iacute;n', 'invoicing'),
901
+        'TAC' => __('Tacna', 'invoicing'),
902
+        'TUM' => __('Tumbes', 'invoicing'),
903
+        'UCA' => __('Ucayali', 'invoicing')
904 904
     );
905 905
 
906
-    return apply_filters( 'wpinv_peru_states', $states );
906
+    return apply_filters('wpinv_peru_states', $states);
907 907
 }
908 908
 
909 909
 function wpinv_get_indonesia_states_list() {
910
-    $states  = array(
911
-        'AC' => __( 'Daerah Istimewa Aceh', 'invoicing' ),
912
-        'SU' => __( 'Sumatera Utara', 'invoicing' ),
913
-        'SB' => __( 'Sumatera Barat', 'invoicing' ),
914
-        'RI' => __( 'Riau', 'invoicing' ),
915
-        'KR' => __( 'Kepulauan Riau', 'invoicing' ),
916
-        'JA' => __( 'Jambi', 'invoicing' ),
917
-        'SS' => __( 'Sumatera Selatan', 'invoicing' ),
918
-        'BB' => __( 'Bangka Belitung', 'invoicing' ),
919
-        'BE' => __( 'Bengkulu', 'invoicing' ),
920
-        'LA' => __( 'Lampung', 'invoicing' ),
921
-        'JK' => __( 'DKI Jakarta', 'invoicing' ),
922
-        'JB' => __( 'Jawa Barat', 'invoicing' ),
923
-        'BT' => __( 'Banten', 'invoicing' ),
924
-        'JT' => __( 'Jawa Tengah', 'invoicing' ),
925
-        'JI' => __( 'Jawa Timur', 'invoicing' ),
926
-        'YO' => __( 'Daerah Istimewa Yogyakarta', 'invoicing' ),
927
-        'BA' => __( 'Bali', 'invoicing' ),
928
-        'NB' => __( 'Nusa Tenggara Barat', 'invoicing' ),
929
-        'NT' => __( 'Nusa Tenggara Timur', 'invoicing' ),
930
-        'KB' => __( 'Kalimantan Barat', 'invoicing' ),
931
-        'KT' => __( 'Kalimantan Tengah', 'invoicing' ),
932
-        'KI' => __( 'Kalimantan Timur', 'invoicing' ),
933
-        'KS' => __( 'Kalimantan Selatan', 'invoicing' ),
934
-        'KU' => __( 'Kalimantan Utara', 'invoicing' ),
935
-        'SA' => __( 'Sulawesi Utara', 'invoicing' ),
936
-        'ST' => __( 'Sulawesi Tengah', 'invoicing' ),
937
-        'SG' => __( 'Sulawesi Tenggara', 'invoicing' ),
938
-        'SR' => __( 'Sulawesi Barat', 'invoicing' ),
939
-        'SN' => __( 'Sulawesi Selatan', 'invoicing' ),
940
-        'GO' => __( 'Gorontalo', 'invoicing' ),
941
-        'MA' => __( 'Maluku', 'invoicing' ),
942
-        'MU' => __( 'Maluku Utara', 'invoicing' ),
943
-        'PA' => __( 'Papua', 'invoicing' ),
944
-        'PB' => __( 'Papua Barat', 'invoicing' )
910
+    $states = array(
911
+        'AC' => __('Daerah Istimewa Aceh', 'invoicing'),
912
+        'SU' => __('Sumatera Utara', 'invoicing'),
913
+        'SB' => __('Sumatera Barat', 'invoicing'),
914
+        'RI' => __('Riau', 'invoicing'),
915
+        'KR' => __('Kepulauan Riau', 'invoicing'),
916
+        'JA' => __('Jambi', 'invoicing'),
917
+        'SS' => __('Sumatera Selatan', 'invoicing'),
918
+        'BB' => __('Bangka Belitung', 'invoicing'),
919
+        'BE' => __('Bengkulu', 'invoicing'),
920
+        'LA' => __('Lampung', 'invoicing'),
921
+        'JK' => __('DKI Jakarta', 'invoicing'),
922
+        'JB' => __('Jawa Barat', 'invoicing'),
923
+        'BT' => __('Banten', 'invoicing'),
924
+        'JT' => __('Jawa Tengah', 'invoicing'),
925
+        'JI' => __('Jawa Timur', 'invoicing'),
926
+        'YO' => __('Daerah Istimewa Yogyakarta', 'invoicing'),
927
+        'BA' => __('Bali', 'invoicing'),
928
+        'NB' => __('Nusa Tenggara Barat', 'invoicing'),
929
+        'NT' => __('Nusa Tenggara Timur', 'invoicing'),
930
+        'KB' => __('Kalimantan Barat', 'invoicing'),
931
+        'KT' => __('Kalimantan Tengah', 'invoicing'),
932
+        'KI' => __('Kalimantan Timur', 'invoicing'),
933
+        'KS' => __('Kalimantan Selatan', 'invoicing'),
934
+        'KU' => __('Kalimantan Utara', 'invoicing'),
935
+        'SA' => __('Sulawesi Utara', 'invoicing'),
936
+        'ST' => __('Sulawesi Tengah', 'invoicing'),
937
+        'SG' => __('Sulawesi Tenggara', 'invoicing'),
938
+        'SR' => __('Sulawesi Barat', 'invoicing'),
939
+        'SN' => __('Sulawesi Selatan', 'invoicing'),
940
+        'GO' => __('Gorontalo', 'invoicing'),
941
+        'MA' => __('Maluku', 'invoicing'),
942
+        'MU' => __('Maluku Utara', 'invoicing'),
943
+        'PA' => __('Papua', 'invoicing'),
944
+        'PB' => __('Papua Barat', 'invoicing')
945 945
     );
946 946
 
947
-    return apply_filters( 'wpinv_indonesia_states', $states );
947
+    return apply_filters('wpinv_indonesia_states', $states);
948 948
 }
949 949
 
950 950
 function wpinv_get_india_states_list() {
951 951
     $states = array(
952
-        'AP' => __( 'Andhra Pradesh', 'invoicing' ),
953
-        'AR' => __( 'Arunachal Pradesh', 'invoicing' ),
954
-        'AS' => __( 'Assam', 'invoicing' ),
955
-        'BR' => __( 'Bihar', 'invoicing' ),
956
-        'CT' => __( 'Chhattisgarh', 'invoicing' ),
957
-        'GA' => __( 'Goa', 'invoicing' ),
958
-        'GJ' => __( 'Gujarat', 'invoicing' ),
959
-        'HR' => __( 'Haryana', 'invoicing' ),
960
-        'HP' => __( 'Himachal Pradesh', 'invoicing' ),
961
-        'JK' => __( 'Jammu and Kashmir', 'invoicing' ),
962
-        'JH' => __( 'Jharkhand', 'invoicing' ),
963
-        'KA' => __( 'Karnataka', 'invoicing' ),
964
-        'KL' => __( 'Kerala', 'invoicing' ),
965
-        'MP' => __( 'Madhya Pradesh', 'invoicing' ),
966
-        'MH' => __( 'Maharashtra', 'invoicing' ),
967
-        'MN' => __( 'Manipur', 'invoicing' ),
968
-        'ML' => __( 'Meghalaya', 'invoicing' ),
969
-        'MZ' => __( 'Mizoram', 'invoicing' ),
970
-        'NL' => __( 'Nagaland', 'invoicing' ),
971
-        'OR' => __( 'Orissa', 'invoicing' ),
972
-        'PB' => __( 'Punjab', 'invoicing' ),
973
-        'RJ' => __( 'Rajasthan', 'invoicing' ),
974
-        'SK' => __( 'Sikkim', 'invoicing' ),
975
-        'TN' => __( 'Tamil Nadu', 'invoicing' ),
976
-        'TG' => __( 'Telangana', 'invoicing' ),
977
-        'TR' => __( 'Tripura', 'invoicing' ),
978
-        'UT' => __( 'Uttarakhand', 'invoicing' ),
979
-        'UP' => __( 'Uttar Pradesh', 'invoicing' ),
980
-        'WB' => __( 'West Bengal', 'invoicing' ),
981
-        'AN' => __( 'Andaman and Nicobar Islands', 'invoicing' ),
982
-        'CH' => __( 'Chandigarh', 'invoicing' ),
983
-        'DN' => __( 'Dadar and Nagar Haveli', 'invoicing' ),
984
-        'DD' => __( 'Daman and Diu', 'invoicing' ),
985
-        'DL' => __( 'Delhi', 'invoicing' ),
986
-        'LD' => __( 'Lakshadweep', 'invoicing' ),
987
-        'PY' => __( 'Pondicherry (Puducherry)', 'invoicing' )
952
+        'AP' => __('Andhra Pradesh', 'invoicing'),
953
+        'AR' => __('Arunachal Pradesh', 'invoicing'),
954
+        'AS' => __('Assam', 'invoicing'),
955
+        'BR' => __('Bihar', 'invoicing'),
956
+        'CT' => __('Chhattisgarh', 'invoicing'),
957
+        'GA' => __('Goa', 'invoicing'),
958
+        'GJ' => __('Gujarat', 'invoicing'),
959
+        'HR' => __('Haryana', 'invoicing'),
960
+        'HP' => __('Himachal Pradesh', 'invoicing'),
961
+        'JK' => __('Jammu and Kashmir', 'invoicing'),
962
+        'JH' => __('Jharkhand', 'invoicing'),
963
+        'KA' => __('Karnataka', 'invoicing'),
964
+        'KL' => __('Kerala', 'invoicing'),
965
+        'MP' => __('Madhya Pradesh', 'invoicing'),
966
+        'MH' => __('Maharashtra', 'invoicing'),
967
+        'MN' => __('Manipur', 'invoicing'),
968
+        'ML' => __('Meghalaya', 'invoicing'),
969
+        'MZ' => __('Mizoram', 'invoicing'),
970
+        'NL' => __('Nagaland', 'invoicing'),
971
+        'OR' => __('Orissa', 'invoicing'),
972
+        'PB' => __('Punjab', 'invoicing'),
973
+        'RJ' => __('Rajasthan', 'invoicing'),
974
+        'SK' => __('Sikkim', 'invoicing'),
975
+        'TN' => __('Tamil Nadu', 'invoicing'),
976
+        'TG' => __('Telangana', 'invoicing'),
977
+        'TR' => __('Tripura', 'invoicing'),
978
+        'UT' => __('Uttarakhand', 'invoicing'),
979
+        'UP' => __('Uttar Pradesh', 'invoicing'),
980
+        'WB' => __('West Bengal', 'invoicing'),
981
+        'AN' => __('Andaman and Nicobar Islands', 'invoicing'),
982
+        'CH' => __('Chandigarh', 'invoicing'),
983
+        'DN' => __('Dadar and Nagar Haveli', 'invoicing'),
984
+        'DD' => __('Daman and Diu', 'invoicing'),
985
+        'DL' => __('Delhi', 'invoicing'),
986
+        'LD' => __('Lakshadweep', 'invoicing'),
987
+        'PY' => __('Pondicherry (Puducherry)', 'invoicing')
988 988
     );
989 989
 
990
-    return apply_filters( 'wpinv_india_states', $states );
990
+    return apply_filters('wpinv_india_states', $states);
991 991
 }
992 992
 
993 993
 function wpinv_get_iran_states_list() {
994 994
     $states = array(
995
-        'KHZ' => __( 'Khuzestan', 'invoicing' ),
996
-        'THR' => __( 'Tehran', 'invoicing' ),
997
-        'ILM' => __( 'Ilaam', 'invoicing' ),
998
-        'BHR' => __( 'Bushehr', 'invoicing' ),
999
-        'ADL' => __( 'Ardabil', 'invoicing' ),
1000
-        'ESF' => __( 'Isfahan', 'invoicing' ),
1001
-        'YZD' => __( 'Yazd', 'invoicing' ),
1002
-        'KRH' => __( 'Kermanshah', 'invoicing' ),
1003
-        'KRN' => __( 'Kerman', 'invoicing' ),
1004
-        'HDN' => __( 'Hamadan', 'invoicing' ),
1005
-        'GZN' => __( 'Ghazvin', 'invoicing' ),
1006
-        'ZJN' => __( 'Zanjan', 'invoicing' ),
1007
-        'LRS' => __( 'Luristan', 'invoicing' ),
1008
-        'ABZ' => __( 'Alborz', 'invoicing' ),
1009
-        'EAZ' => __( 'East Azerbaijan', 'invoicing' ),
1010
-        'WAZ' => __( 'West Azerbaijan', 'invoicing' ),
1011
-        'CHB' => __( 'Chaharmahal and Bakhtiari', 'invoicing' ),
1012
-        'SKH' => __( 'South Khorasan', 'invoicing' ),
1013
-        'RKH' => __( 'Razavi Khorasan', 'invoicing' ),
1014
-        'NKH' => __( 'North Khorasan', 'invoicing' ),
1015
-        'SMN' => __( 'Semnan', 'invoicing' ),
1016
-        'FRS' => __( 'Fars', 'invoicing' ),
1017
-        'QHM' => __( 'Qom', 'invoicing' ),
1018
-        'KRD' => __( 'Kurdistan', 'invoicing' ),
1019
-        'KBD' => __( 'Kohgiluyeh and BoyerAhmad', 'invoicing' ),
1020
-        'GLS' => __( 'Golestan', 'invoicing' ),
1021
-        'GIL' => __( 'Gilan', 'invoicing' ),
1022
-        'MZN' => __( 'Mazandaran', 'invoicing' ),
1023
-        'MKZ' => __( 'Markazi', 'invoicing' ),
1024
-        'HRZ' => __( 'Hormozgan', 'invoicing' ),
1025
-        'SBN' => __( 'Sistan and Baluchestan', 'invoicing' )
995
+        'KHZ' => __('Khuzestan', 'invoicing'),
996
+        'THR' => __('Tehran', 'invoicing'),
997
+        'ILM' => __('Ilaam', 'invoicing'),
998
+        'BHR' => __('Bushehr', 'invoicing'),
999
+        'ADL' => __('Ardabil', 'invoicing'),
1000
+        'ESF' => __('Isfahan', 'invoicing'),
1001
+        'YZD' => __('Yazd', 'invoicing'),
1002
+        'KRH' => __('Kermanshah', 'invoicing'),
1003
+        'KRN' => __('Kerman', 'invoicing'),
1004
+        'HDN' => __('Hamadan', 'invoicing'),
1005
+        'GZN' => __('Ghazvin', 'invoicing'),
1006
+        'ZJN' => __('Zanjan', 'invoicing'),
1007
+        'LRS' => __('Luristan', 'invoicing'),
1008
+        'ABZ' => __('Alborz', 'invoicing'),
1009
+        'EAZ' => __('East Azerbaijan', 'invoicing'),
1010
+        'WAZ' => __('West Azerbaijan', 'invoicing'),
1011
+        'CHB' => __('Chaharmahal and Bakhtiari', 'invoicing'),
1012
+        'SKH' => __('South Khorasan', 'invoicing'),
1013
+        'RKH' => __('Razavi Khorasan', 'invoicing'),
1014
+        'NKH' => __('North Khorasan', 'invoicing'),
1015
+        'SMN' => __('Semnan', 'invoicing'),
1016
+        'FRS' => __('Fars', 'invoicing'),
1017
+        'QHM' => __('Qom', 'invoicing'),
1018
+        'KRD' => __('Kurdistan', 'invoicing'),
1019
+        'KBD' => __('Kohgiluyeh and BoyerAhmad', 'invoicing'),
1020
+        'GLS' => __('Golestan', 'invoicing'),
1021
+        'GIL' => __('Gilan', 'invoicing'),
1022
+        'MZN' => __('Mazandaran', 'invoicing'),
1023
+        'MKZ' => __('Markazi', 'invoicing'),
1024
+        'HRZ' => __('Hormozgan', 'invoicing'),
1025
+        'SBN' => __('Sistan and Baluchestan', 'invoicing')
1026 1026
     );
1027 1027
 
1028
-    return apply_filters( 'wpinv_iran_states', $states );
1028
+    return apply_filters('wpinv_iran_states', $states);
1029 1029
 }
1030 1030
 
1031 1031
 function wpinv_get_italy_states_list() {
1032 1032
     $states = array(
1033
-        'AG' => __( 'Agrigento', 'invoicing' ),
1034
-        'AL' => __( 'Alessandria', 'invoicing' ),
1035
-        'AN' => __( 'Ancona', 'invoicing' ),
1036
-        'AO' => __( 'Aosta', 'invoicing' ),
1037
-        'AR' => __( 'Arezzo', 'invoicing' ),
1038
-        'AP' => __( 'Ascoli Piceno', 'invoicing' ),
1039
-        'AT' => __( 'Asti', 'invoicing' ),
1040
-        'AV' => __( 'Avellino', 'invoicing' ),
1041
-        'BA' => __( 'Bari', 'invoicing' ),
1042
-        'BT' => __( 'Barletta-Andria-Trani', 'invoicing' ),
1043
-        'BL' => __( 'Belluno', 'invoicing' ),
1044
-        'BN' => __( 'Benevento', 'invoicing' ),
1045
-        'BG' => __( 'Bergamo', 'invoicing' ),
1046
-        'BI' => __( 'Biella', 'invoicing' ),
1047
-        'BO' => __( 'Bologna', 'invoicing' ),
1048
-        'BZ' => __( 'Bolzano', 'invoicing' ),
1049
-        'BS' => __( 'Brescia', 'invoicing' ),
1050
-        'BR' => __( 'Brindisi', 'invoicing' ),
1051
-        'CA' => __( 'Cagliari', 'invoicing' ),
1052
-        'CL' => __( 'Caltanissetta', 'invoicing' ),
1053
-        'CB' => __( 'Campobasso', 'invoicing' ),
1054
-        'CI' => __( 'Caltanissetta', 'invoicing' ),
1055
-        'CE' => __( 'Caserta', 'invoicing' ),
1056
-        'CT' => __( 'Catania', 'invoicing' ),
1057
-        'CZ' => __( 'Catanzaro', 'invoicing' ),
1058
-        'CH' => __( 'Chieti', 'invoicing' ),
1059
-        'CO' => __( 'Como', 'invoicing' ),
1060
-        'CS' => __( 'Cosenza', 'invoicing' ),
1061
-        'CR' => __( 'Cremona', 'invoicing' ),
1062
-        'KR' => __( 'Crotone', 'invoicing' ),
1063
-        'CN' => __( 'Cuneo', 'invoicing' ),
1064
-        'EN' => __( 'Enna', 'invoicing' ),
1065
-        'FM' => __( 'Fermo', 'invoicing' ),
1066
-        'FE' => __( 'Ferrara', 'invoicing' ),
1067
-        'FI' => __( 'Firenze', 'invoicing' ),
1068
-        'FG' => __( 'Foggia', 'invoicing' ),
1069
-        'FC' => __( 'Forli-Cesena', 'invoicing' ),
1070
-        'FR' => __( 'Frosinone', 'invoicing' ),
1071
-        'GE' => __( 'Genova', 'invoicing' ),
1072
-        'GO' => __( 'Gorizia', 'invoicing' ),
1073
-        'GR' => __( 'Grosseto', 'invoicing' ),
1074
-        'IM' => __( 'Imperia', 'invoicing' ),
1075
-        'IS' => __( 'Isernia', 'invoicing' ),
1076
-        'SP' => __( 'La Spezia', 'invoicing' ),
1077
-        'AQ' => __( 'L&apos;Aquila', 'invoicing' ),
1078
-        'LT' => __( 'Latina', 'invoicing' ),
1079
-        'LE' => __( 'Lecce', 'invoicing' ),
1080
-        'LC' => __( 'Lecco', 'invoicing' ),
1081
-        'LI' => __( 'Livorno', 'invoicing' ),
1082
-        'LO' => __( 'Lodi', 'invoicing' ),
1083
-        'LU' => __( 'Lucca', 'invoicing' ),
1084
-        'MC' => __( 'Macerata', 'invoicing' ),
1085
-        'MN' => __( 'Mantova', 'invoicing' ),
1086
-        'MS' => __( 'Massa-Carrara', 'invoicing' ),
1087
-        'MT' => __( 'Matera', 'invoicing' ),
1088
-        'ME' => __( 'Messina', 'invoicing' ),
1089
-        'MI' => __( 'Milano', 'invoicing' ),
1090
-        'MO' => __( 'Modena', 'invoicing' ),
1091
-        'MB' => __( 'Monza e della Brianza', 'invoicing' ),
1092
-        'NA' => __( 'Napoli', 'invoicing' ),
1093
-        'NO' => __( 'Novara', 'invoicing' ),
1094
-        'NU' => __( 'Nuoro', 'invoicing' ),
1095
-        'OT' => __( 'Olbia-Tempio', 'invoicing' ),
1096
-        'OR' => __( 'Oristano', 'invoicing' ),
1097
-        'PD' => __( 'Padova', 'invoicing' ),
1098
-        'PA' => __( 'Palermo', 'invoicing' ),
1099
-        'PR' => __( 'Parma', 'invoicing' ),
1100
-        'PV' => __( 'Pavia', 'invoicing' ),
1101
-        'PG' => __( 'Perugia', 'invoicing' ),
1102
-        'PU' => __( 'Pesaro e Urbino', 'invoicing' ),
1103
-        'PE' => __( 'Pescara', 'invoicing' ),
1104
-        'PC' => __( 'Piacenza', 'invoicing' ),
1105
-        'PI' => __( 'Pisa', 'invoicing' ),
1106
-        'PT' => __( 'Pistoia', 'invoicing' ),
1107
-        'PN' => __( 'Pordenone', 'invoicing' ),
1108
-        'PZ' => __( 'Potenza', 'invoicing' ),
1109
-        'PO' => __( 'Prato', 'invoicing' ),
1110
-        'RG' => __( 'Ragusa', 'invoicing' ),
1111
-        'RA' => __( 'Ravenna', 'invoicing' ),
1112
-        'RC' => __( 'Reggio Calabria', 'invoicing' ),
1113
-        'RE' => __( 'Reggio Emilia', 'invoicing' ),
1114
-        'RI' => __( 'Rieti', 'invoicing' ),
1115
-        'RN' => __( 'Rimini', 'invoicing' ),
1116
-        'RM' => __( 'Roma', 'invoicing' ),
1117
-        'RO' => __( 'Rovigo', 'invoicing' ),
1118
-        'SA' => __( 'Salerno', 'invoicing' ),
1119
-        'VS' => __( 'Medio Campidano', 'invoicing' ),
1120
-        'SS' => __( 'Sassari', 'invoicing' ),
1121
-        'SV' => __( 'Savona', 'invoicing' ),
1122
-        'SI' => __( 'Siena', 'invoicing' ),
1123
-        'SR' => __( 'Siracusa', 'invoicing' ),
1124
-        'SO' => __( 'Sondrio', 'invoicing' ),
1125
-        'TA' => __( 'Taranto', 'invoicing' ),
1126
-        'TE' => __( 'Teramo', 'invoicing' ),
1127
-        'TR' => __( 'Terni', 'invoicing' ),
1128
-        'TO' => __( 'Torino', 'invoicing' ),
1129
-        'OG' => __( 'Ogliastra', 'invoicing' ),
1130
-        'TP' => __( 'Trapani', 'invoicing' ),
1131
-        'TN' => __( 'Trento', 'invoicing' ),
1132
-        'TV' => __( 'Treviso', 'invoicing' ),
1133
-        'TS' => __( 'Trieste', 'invoicing' ),
1134
-        'UD' => __( 'Udine', 'invoicing' ),
1135
-        'VA' => __( 'Varesa', 'invoicing' ),
1136
-        'VE' => __( 'Venezia', 'invoicing' ),
1137
-        'VB' => __( 'Verbano-Cusio-Ossola', 'invoicing' ),
1138
-        'VC' => __( 'Vercelli', 'invoicing' ),
1139
-        'VR' => __( 'Verona', 'invoicing' ),
1140
-        'VV' => __( 'Vibo Valentia', 'invoicing' ),
1141
-        'VI' => __( 'Vicenza', 'invoicing' ),
1142
-        'VT' => __( 'Viterbo', 'invoicing' )
1033
+        'AG' => __('Agrigento', 'invoicing'),
1034
+        'AL' => __('Alessandria', 'invoicing'),
1035
+        'AN' => __('Ancona', 'invoicing'),
1036
+        'AO' => __('Aosta', 'invoicing'),
1037
+        'AR' => __('Arezzo', 'invoicing'),
1038
+        'AP' => __('Ascoli Piceno', 'invoicing'),
1039
+        'AT' => __('Asti', 'invoicing'),
1040
+        'AV' => __('Avellino', 'invoicing'),
1041
+        'BA' => __('Bari', 'invoicing'),
1042
+        'BT' => __('Barletta-Andria-Trani', 'invoicing'),
1043
+        'BL' => __('Belluno', 'invoicing'),
1044
+        'BN' => __('Benevento', 'invoicing'),
1045
+        'BG' => __('Bergamo', 'invoicing'),
1046
+        'BI' => __('Biella', 'invoicing'),
1047
+        'BO' => __('Bologna', 'invoicing'),
1048
+        'BZ' => __('Bolzano', 'invoicing'),
1049
+        'BS' => __('Brescia', 'invoicing'),
1050
+        'BR' => __('Brindisi', 'invoicing'),
1051
+        'CA' => __('Cagliari', 'invoicing'),
1052
+        'CL' => __('Caltanissetta', 'invoicing'),
1053
+        'CB' => __('Campobasso', 'invoicing'),
1054
+        'CI' => __('Caltanissetta', 'invoicing'),
1055
+        'CE' => __('Caserta', 'invoicing'),
1056
+        'CT' => __('Catania', 'invoicing'),
1057
+        'CZ' => __('Catanzaro', 'invoicing'),
1058
+        'CH' => __('Chieti', 'invoicing'),
1059
+        'CO' => __('Como', 'invoicing'),
1060
+        'CS' => __('Cosenza', 'invoicing'),
1061
+        'CR' => __('Cremona', 'invoicing'),
1062
+        'KR' => __('Crotone', 'invoicing'),
1063
+        'CN' => __('Cuneo', 'invoicing'),
1064
+        'EN' => __('Enna', 'invoicing'),
1065
+        'FM' => __('Fermo', 'invoicing'),
1066
+        'FE' => __('Ferrara', 'invoicing'),
1067
+        'FI' => __('Firenze', 'invoicing'),
1068
+        'FG' => __('Foggia', 'invoicing'),
1069
+        'FC' => __('Forli-Cesena', 'invoicing'),
1070
+        'FR' => __('Frosinone', 'invoicing'),
1071
+        'GE' => __('Genova', 'invoicing'),
1072
+        'GO' => __('Gorizia', 'invoicing'),
1073
+        'GR' => __('Grosseto', 'invoicing'),
1074
+        'IM' => __('Imperia', 'invoicing'),
1075
+        'IS' => __('Isernia', 'invoicing'),
1076
+        'SP' => __('La Spezia', 'invoicing'),
1077
+        'AQ' => __('L&apos;Aquila', 'invoicing'),
1078
+        'LT' => __('Latina', 'invoicing'),
1079
+        'LE' => __('Lecce', 'invoicing'),
1080
+        'LC' => __('Lecco', 'invoicing'),
1081
+        'LI' => __('Livorno', 'invoicing'),
1082
+        'LO' => __('Lodi', 'invoicing'),
1083
+        'LU' => __('Lucca', 'invoicing'),
1084
+        'MC' => __('Macerata', 'invoicing'),
1085
+        'MN' => __('Mantova', 'invoicing'),
1086
+        'MS' => __('Massa-Carrara', 'invoicing'),
1087
+        'MT' => __('Matera', 'invoicing'),
1088
+        'ME' => __('Messina', 'invoicing'),
1089
+        'MI' => __('Milano', 'invoicing'),
1090
+        'MO' => __('Modena', 'invoicing'),
1091
+        'MB' => __('Monza e della Brianza', 'invoicing'),
1092
+        'NA' => __('Napoli', 'invoicing'),
1093
+        'NO' => __('Novara', 'invoicing'),
1094
+        'NU' => __('Nuoro', 'invoicing'),
1095
+        'OT' => __('Olbia-Tempio', 'invoicing'),
1096
+        'OR' => __('Oristano', 'invoicing'),
1097
+        'PD' => __('Padova', 'invoicing'),
1098
+        'PA' => __('Palermo', 'invoicing'),
1099
+        'PR' => __('Parma', 'invoicing'),
1100
+        'PV' => __('Pavia', 'invoicing'),
1101
+        'PG' => __('Perugia', 'invoicing'),
1102
+        'PU' => __('Pesaro e Urbino', 'invoicing'),
1103
+        'PE' => __('Pescara', 'invoicing'),
1104
+        'PC' => __('Piacenza', 'invoicing'),
1105
+        'PI' => __('Pisa', 'invoicing'),
1106
+        'PT' => __('Pistoia', 'invoicing'),
1107
+        'PN' => __('Pordenone', 'invoicing'),
1108
+        'PZ' => __('Potenza', 'invoicing'),
1109
+        'PO' => __('Prato', 'invoicing'),
1110
+        'RG' => __('Ragusa', 'invoicing'),
1111
+        'RA' => __('Ravenna', 'invoicing'),
1112
+        'RC' => __('Reggio Calabria', 'invoicing'),
1113
+        'RE' => __('Reggio Emilia', 'invoicing'),
1114
+        'RI' => __('Rieti', 'invoicing'),
1115
+        'RN' => __('Rimini', 'invoicing'),
1116
+        'RM' => __('Roma', 'invoicing'),
1117
+        'RO' => __('Rovigo', 'invoicing'),
1118
+        'SA' => __('Salerno', 'invoicing'),
1119
+        'VS' => __('Medio Campidano', 'invoicing'),
1120
+        'SS' => __('Sassari', 'invoicing'),
1121
+        'SV' => __('Savona', 'invoicing'),
1122
+        'SI' => __('Siena', 'invoicing'),
1123
+        'SR' => __('Siracusa', 'invoicing'),
1124
+        'SO' => __('Sondrio', 'invoicing'),
1125
+        'TA' => __('Taranto', 'invoicing'),
1126
+        'TE' => __('Teramo', 'invoicing'),
1127
+        'TR' => __('Terni', 'invoicing'),
1128
+        'TO' => __('Torino', 'invoicing'),
1129
+        'OG' => __('Ogliastra', 'invoicing'),
1130
+        'TP' => __('Trapani', 'invoicing'),
1131
+        'TN' => __('Trento', 'invoicing'),
1132
+        'TV' => __('Treviso', 'invoicing'),
1133
+        'TS' => __('Trieste', 'invoicing'),
1134
+        'UD' => __('Udine', 'invoicing'),
1135
+        'VA' => __('Varesa', 'invoicing'),
1136
+        'VE' => __('Venezia', 'invoicing'),
1137
+        'VB' => __('Verbano-Cusio-Ossola', 'invoicing'),
1138
+        'VC' => __('Vercelli', 'invoicing'),
1139
+        'VR' => __('Verona', 'invoicing'),
1140
+        'VV' => __('Vibo Valentia', 'invoicing'),
1141
+        'VI' => __('Vicenza', 'invoicing'),
1142
+        'VT' => __('Viterbo', 'invoicing')
1143 1143
     );
1144 1144
 
1145
-    return apply_filters( 'wpinv_italy_states', $states );
1145
+    return apply_filters('wpinv_italy_states', $states);
1146 1146
 }
1147 1147
 
1148 1148
 function wpinv_get_malaysia_states_list() {
1149 1149
     $states = array(
1150
-        'JHR' => __( 'Johor', 'invoicing' ),
1151
-        'KDH' => __( 'Kedah', 'invoicing' ),
1152
-        'KTN' => __( 'Kelantan', 'invoicing' ),
1153
-        'MLK' => __( 'Melaka', 'invoicing' ),
1154
-        'NSN' => __( 'Negeri Sembilan', 'invoicing' ),
1155
-        'PHG' => __( 'Pahang', 'invoicing' ),
1156
-        'PRK' => __( 'Perak', 'invoicing' ),
1157
-        'PLS' => __( 'Perlis', 'invoicing' ),
1158
-        'PNG' => __( 'Pulau Pinang', 'invoicing' ),
1159
-        'SBH' => __( 'Sabah', 'invoicing' ),
1160
-        'SWK' => __( 'Sarawak', 'invoicing' ),
1161
-        'SGR' => __( 'Selangor', 'invoicing' ),
1162
-        'TRG' => __( 'Terengganu', 'invoicing' ),
1163
-        'KUL' => __( 'W.P. Kuala Lumpur', 'invoicing' ),
1164
-        'LBN' => __( 'W.P. Labuan', 'invoicing' ),
1165
-        'PJY' => __( 'W.P. Putrajaya', 'invoicing' )
1150
+        'JHR' => __('Johor', 'invoicing'),
1151
+        'KDH' => __('Kedah', 'invoicing'),
1152
+        'KTN' => __('Kelantan', 'invoicing'),
1153
+        'MLK' => __('Melaka', 'invoicing'),
1154
+        'NSN' => __('Negeri Sembilan', 'invoicing'),
1155
+        'PHG' => __('Pahang', 'invoicing'),
1156
+        'PRK' => __('Perak', 'invoicing'),
1157
+        'PLS' => __('Perlis', 'invoicing'),
1158
+        'PNG' => __('Pulau Pinang', 'invoicing'),
1159
+        'SBH' => __('Sabah', 'invoicing'),
1160
+        'SWK' => __('Sarawak', 'invoicing'),
1161
+        'SGR' => __('Selangor', 'invoicing'),
1162
+        'TRG' => __('Terengganu', 'invoicing'),
1163
+        'KUL' => __('W.P. Kuala Lumpur', 'invoicing'),
1164
+        'LBN' => __('W.P. Labuan', 'invoicing'),
1165
+        'PJY' => __('W.P. Putrajaya', 'invoicing')
1166 1166
     );
1167 1167
 
1168
-    return apply_filters( 'wpinv_malaysia_states', $states );
1168
+    return apply_filters('wpinv_malaysia_states', $states);
1169 1169
 }
1170 1170
 
1171 1171
 function wpinv_get_mexico_states_list() {
1172 1172
     $states = array(
1173
-        'DIF' => __( 'Distrito Federal', 'invoicing' ),
1174
-        'JAL' => __( 'Jalisco', 'invoicing' ),
1175
-        'NLE' => __( 'Nuevo Le&oacute;n', 'invoicing' ),
1176
-        'AGU' => __( 'Aguascalientes', 'invoicing' ),
1177
-        'BCN' => __( 'Baja California Norte', 'invoicing' ),
1178
-        'BCS' => __( 'Baja California Sur', 'invoicing' ),
1179
-        'CAM' => __( 'Campeche', 'invoicing' ),
1180
-        'CHP' => __( 'Chiapas', 'invoicing' ),
1181
-        'CHH' => __( 'Chihuahua', 'invoicing' ),
1182
-        'COA' => __( 'Coahuila', 'invoicing' ),
1183
-        'COL' => __( 'Colima', 'invoicing' ),
1184
-        'DUR' => __( 'Durango', 'invoicing' ),
1185
-        'GUA' => __( 'Guanajuato', 'invoicing' ),
1186
-        'GRO' => __( 'Guerrero', 'invoicing' ),
1187
-        'HID' => __( 'Hidalgo', 'invoicing' ),
1188
-        'MEX' => __( 'Edo. de M&eacute;xico', 'invoicing' ),
1189
-        'MIC' => __( 'Michoac&aacute;n', 'invoicing' ),
1190
-        'MOR' => __( 'Morelos', 'invoicing' ),
1191
-        'NAY' => __( 'Nayarit', 'invoicing' ),
1192
-        'OAX' => __( 'Oaxaca', 'invoicing' ),
1193
-        'PUE' => __( 'Puebla', 'invoicing' ),
1194
-        'QUE' => __( 'Quer&eacute;taro', 'invoicing' ),
1195
-        'ROO' => __( 'Quintana Roo', 'invoicing' ),
1196
-        'SLP' => __( 'San Luis Potos&iacute;', 'invoicing' ),
1197
-        'SIN' => __( 'Sinaloa', 'invoicing' ),
1198
-        'SON' => __( 'Sonora', 'invoicing' ),
1199
-        'TAB' => __( 'Tabasco', 'invoicing' ),
1200
-        'TAM' => __( 'Tamaulipas', 'invoicing' ),
1201
-        'TLA' => __( 'Tlaxcala', 'invoicing' ),
1202
-        'VER' => __( 'Veracruz', 'invoicing' ),
1203
-        'YUC' => __( 'Yucat&aacute;n', 'invoicing' ),
1204
-        'ZAC' => __( 'Zacatecas', 'invoicing' )
1173
+        'DIF' => __('Distrito Federal', 'invoicing'),
1174
+        'JAL' => __('Jalisco', 'invoicing'),
1175
+        'NLE' => __('Nuevo Le&oacute;n', 'invoicing'),
1176
+        'AGU' => __('Aguascalientes', 'invoicing'),
1177
+        'BCN' => __('Baja California Norte', 'invoicing'),
1178
+        'BCS' => __('Baja California Sur', 'invoicing'),
1179
+        'CAM' => __('Campeche', 'invoicing'),
1180
+        'CHP' => __('Chiapas', 'invoicing'),
1181
+        'CHH' => __('Chihuahua', 'invoicing'),
1182
+        'COA' => __('Coahuila', 'invoicing'),
1183
+        'COL' => __('Colima', 'invoicing'),
1184
+        'DUR' => __('Durango', 'invoicing'),
1185
+        'GUA' => __('Guanajuato', 'invoicing'),
1186
+        'GRO' => __('Guerrero', 'invoicing'),
1187
+        'HID' => __('Hidalgo', 'invoicing'),
1188
+        'MEX' => __('Edo. de M&eacute;xico', 'invoicing'),
1189
+        'MIC' => __('Michoac&aacute;n', 'invoicing'),
1190
+        'MOR' => __('Morelos', 'invoicing'),
1191
+        'NAY' => __('Nayarit', 'invoicing'),
1192
+        'OAX' => __('Oaxaca', 'invoicing'),
1193
+        'PUE' => __('Puebla', 'invoicing'),
1194
+        'QUE' => __('Quer&eacute;taro', 'invoicing'),
1195
+        'ROO' => __('Quintana Roo', 'invoicing'),
1196
+        'SLP' => __('San Luis Potos&iacute;', 'invoicing'),
1197
+        'SIN' => __('Sinaloa', 'invoicing'),
1198
+        'SON' => __('Sonora', 'invoicing'),
1199
+        'TAB' => __('Tabasco', 'invoicing'),
1200
+        'TAM' => __('Tamaulipas', 'invoicing'),
1201
+        'TLA' => __('Tlaxcala', 'invoicing'),
1202
+        'VER' => __('Veracruz', 'invoicing'),
1203
+        'YUC' => __('Yucat&aacute;n', 'invoicing'),
1204
+        'ZAC' => __('Zacatecas', 'invoicing')
1205 1205
     );
1206 1206
 
1207
-    return apply_filters( 'wpinv_mexico_states', $states );
1207
+    return apply_filters('wpinv_mexico_states', $states);
1208 1208
 }
1209 1209
 
1210 1210
 function wpinv_get_nepal_states_list() {
1211 1211
     $states = array(
1212
-        'ILL' => __( 'Illam', 'invoicing' ),
1213
-        'JHA' => __( 'Jhapa', 'invoicing' ),
1214
-        'PAN' => __( 'Panchthar', 'invoicing' ),
1215
-        'TAP' => __( 'Taplejung', 'invoicing' ),
1216
-        'BHO' => __( 'Bhojpur', 'invoicing' ),
1217
-        'DKA' => __( 'Dhankuta', 'invoicing' ),
1218
-        'MOR' => __( 'Morang', 'invoicing' ),
1219
-        'SUN' => __( 'Sunsari', 'invoicing' ),
1220
-        'SAN' => __( 'Sankhuwa', 'invoicing' ),
1221
-        'TER' => __( 'Terhathum', 'invoicing' ),
1222
-        'KHO' => __( 'Khotang', 'invoicing' ),
1223
-        'OKH' => __( 'Okhaldhunga', 'invoicing' ),
1224
-        'SAP' => __( 'Saptari', 'invoicing' ),
1225
-        'SIR' => __( 'Siraha', 'invoicing' ),
1226
-        'SOL' => __( 'Solukhumbu', 'invoicing' ),
1227
-        'UDA' => __( 'Udayapur', 'invoicing' ),
1228
-        'DHA' => __( 'Dhanusa', 'invoicing' ),
1229
-        'DLK' => __( 'Dolakha', 'invoicing' ),
1230
-        'MOH' => __( 'Mohottari', 'invoicing' ),
1231
-        'RAM' => __( 'Ramechha', 'invoicing' ),
1232
-        'SAR' => __( 'Sarlahi', 'invoicing' ),
1233
-        'SIN' => __( 'Sindhuli', 'invoicing' ),
1234
-        'BHA' => __( 'Bhaktapur', 'invoicing' ),
1235
-        'DHD' => __( 'Dhading', 'invoicing' ),
1236
-        'KTM' => __( 'Kathmandu', 'invoicing' ),
1237
-        'KAV' => __( 'Kavrepalanchowk', 'invoicing' ),
1238
-        'LAL' => __( 'Lalitpur', 'invoicing' ),
1239
-        'NUW' => __( 'Nuwakot', 'invoicing' ),
1240
-        'RAS' => __( 'Rasuwa', 'invoicing' ),
1241
-        'SPC' => __( 'Sindhupalchowk', 'invoicing' ),
1242
-        'BAR' => __( 'Bara', 'invoicing' ),
1243
-        'CHI' => __( 'Chitwan', 'invoicing' ),
1244
-        'MAK' => __( 'Makwanpur', 'invoicing' ),
1245
-        'PAR' => __( 'Parsa', 'invoicing' ),
1246
-        'RAU' => __( 'Rautahat', 'invoicing' ),
1247
-        'GOR' => __( 'Gorkha', 'invoicing' ),
1248
-        'KAS' => __( 'Kaski', 'invoicing' ),
1249
-        'LAM' => __( 'Lamjung', 'invoicing' ),
1250
-        'MAN' => __( 'Manang', 'invoicing' ),
1251
-        'SYN' => __( 'Syangja', 'invoicing' ),
1252
-        'TAN' => __( 'Tanahun', 'invoicing' ),
1253
-        'BAG' => __( 'Baglung', 'invoicing' ),
1254
-        'PBT' => __( 'Parbat', 'invoicing' ),
1255
-        'MUS' => __( 'Mustang', 'invoicing' ),
1256
-        'MYG' => __( 'Myagdi', 'invoicing' ),
1257
-        'AGR' => __( 'Agrghakanchi', 'invoicing' ),
1258
-        'GUL' => __( 'Gulmi', 'invoicing' ),
1259
-        'KAP' => __( 'Kapilbastu', 'invoicing' ),
1260
-        'NAW' => __( 'Nawalparasi', 'invoicing' ),
1261
-        'PAL' => __( 'Palpa', 'invoicing' ),
1262
-        'RUP' => __( 'Rupandehi', 'invoicing' ),
1263
-        'DAN' => __( 'Dang', 'invoicing' ),
1264
-        'PYU' => __( 'Pyuthan', 'invoicing' ),
1265
-        'ROL' => __( 'Rolpa', 'invoicing' ),
1266
-        'RUK' => __( 'Rukum', 'invoicing' ),
1267
-        'SAL' => __( 'Salyan', 'invoicing' ),
1268
-        'BAN' => __( 'Banke', 'invoicing' ),
1269
-        'BDA' => __( 'Bardiya', 'invoicing' ),
1270
-        'DAI' => __( 'Dailekh', 'invoicing' ),
1271
-        'JAJ' => __( 'Jajarkot', 'invoicing' ),
1272
-        'SUR' => __( 'Surkhet', 'invoicing' ),
1273
-        'DOL' => __( 'Dolpa', 'invoicing' ),
1274
-        'HUM' => __( 'Humla', 'invoicing' ),
1275
-        'JUM' => __( 'Jumla', 'invoicing' ),
1276
-        'KAL' => __( 'Kalikot', 'invoicing' ),
1277
-        'MUG' => __( 'Mugu', 'invoicing' ),
1278
-        'ACH' => __( 'Achham', 'invoicing' ),
1279
-        'BJH' => __( 'Bajhang', 'invoicing' ),
1280
-        'BJU' => __( 'Bajura', 'invoicing' ),
1281
-        'DOT' => __( 'Doti', 'invoicing' ),
1282
-        'KAI' => __( 'Kailali', 'invoicing' ),
1283
-        'BAI' => __( 'Baitadi', 'invoicing' ),
1284
-        'DAD' => __( 'Dadeldhura', 'invoicing' ),
1285
-        'DAR' => __( 'Darchula', 'invoicing' ),
1286
-        'KAN' => __( 'Kanchanpur', 'invoicing' )
1212
+        'ILL' => __('Illam', 'invoicing'),
1213
+        'JHA' => __('Jhapa', 'invoicing'),
1214
+        'PAN' => __('Panchthar', 'invoicing'),
1215
+        'TAP' => __('Taplejung', 'invoicing'),
1216
+        'BHO' => __('Bhojpur', 'invoicing'),
1217
+        'DKA' => __('Dhankuta', 'invoicing'),
1218
+        'MOR' => __('Morang', 'invoicing'),
1219
+        'SUN' => __('Sunsari', 'invoicing'),
1220
+        'SAN' => __('Sankhuwa', 'invoicing'),
1221
+        'TER' => __('Terhathum', 'invoicing'),
1222
+        'KHO' => __('Khotang', 'invoicing'),
1223
+        'OKH' => __('Okhaldhunga', 'invoicing'),
1224
+        'SAP' => __('Saptari', 'invoicing'),
1225
+        'SIR' => __('Siraha', 'invoicing'),
1226
+        'SOL' => __('Solukhumbu', 'invoicing'),
1227
+        'UDA' => __('Udayapur', 'invoicing'),
1228
+        'DHA' => __('Dhanusa', 'invoicing'),
1229
+        'DLK' => __('Dolakha', 'invoicing'),
1230
+        'MOH' => __('Mohottari', 'invoicing'),
1231
+        'RAM' => __('Ramechha', 'invoicing'),
1232
+        'SAR' => __('Sarlahi', 'invoicing'),
1233
+        'SIN' => __('Sindhuli', 'invoicing'),
1234
+        'BHA' => __('Bhaktapur', 'invoicing'),
1235
+        'DHD' => __('Dhading', 'invoicing'),
1236
+        'KTM' => __('Kathmandu', 'invoicing'),
1237
+        'KAV' => __('Kavrepalanchowk', 'invoicing'),
1238
+        'LAL' => __('Lalitpur', 'invoicing'),
1239
+        'NUW' => __('Nuwakot', 'invoicing'),
1240
+        'RAS' => __('Rasuwa', 'invoicing'),
1241
+        'SPC' => __('Sindhupalchowk', 'invoicing'),
1242
+        'BAR' => __('Bara', 'invoicing'),
1243
+        'CHI' => __('Chitwan', 'invoicing'),
1244
+        'MAK' => __('Makwanpur', 'invoicing'),
1245
+        'PAR' => __('Parsa', 'invoicing'),
1246
+        'RAU' => __('Rautahat', 'invoicing'),
1247
+        'GOR' => __('Gorkha', 'invoicing'),
1248
+        'KAS' => __('Kaski', 'invoicing'),
1249
+        'LAM' => __('Lamjung', 'invoicing'),
1250
+        'MAN' => __('Manang', 'invoicing'),
1251
+        'SYN' => __('Syangja', 'invoicing'),
1252
+        'TAN' => __('Tanahun', 'invoicing'),
1253
+        'BAG' => __('Baglung', 'invoicing'),
1254
+        'PBT' => __('Parbat', 'invoicing'),
1255
+        'MUS' => __('Mustang', 'invoicing'),
1256
+        'MYG' => __('Myagdi', 'invoicing'),
1257
+        'AGR' => __('Agrghakanchi', 'invoicing'),
1258
+        'GUL' => __('Gulmi', 'invoicing'),
1259
+        'KAP' => __('Kapilbastu', 'invoicing'),
1260
+        'NAW' => __('Nawalparasi', 'invoicing'),
1261
+        'PAL' => __('Palpa', 'invoicing'),
1262
+        'RUP' => __('Rupandehi', 'invoicing'),
1263
+        'DAN' => __('Dang', 'invoicing'),
1264
+        'PYU' => __('Pyuthan', 'invoicing'),
1265
+        'ROL' => __('Rolpa', 'invoicing'),
1266
+        'RUK' => __('Rukum', 'invoicing'),
1267
+        'SAL' => __('Salyan', 'invoicing'),
1268
+        'BAN' => __('Banke', 'invoicing'),
1269
+        'BDA' => __('Bardiya', 'invoicing'),
1270
+        'DAI' => __('Dailekh', 'invoicing'),
1271
+        'JAJ' => __('Jajarkot', 'invoicing'),
1272
+        'SUR' => __('Surkhet', 'invoicing'),
1273
+        'DOL' => __('Dolpa', 'invoicing'),
1274
+        'HUM' => __('Humla', 'invoicing'),
1275
+        'JUM' => __('Jumla', 'invoicing'),
1276
+        'KAL' => __('Kalikot', 'invoicing'),
1277
+        'MUG' => __('Mugu', 'invoicing'),
1278
+        'ACH' => __('Achham', 'invoicing'),
1279
+        'BJH' => __('Bajhang', 'invoicing'),
1280
+        'BJU' => __('Bajura', 'invoicing'),
1281
+        'DOT' => __('Doti', 'invoicing'),
1282
+        'KAI' => __('Kailali', 'invoicing'),
1283
+        'BAI' => __('Baitadi', 'invoicing'),
1284
+        'DAD' => __('Dadeldhura', 'invoicing'),
1285
+        'DAR' => __('Darchula', 'invoicing'),
1286
+        'KAN' => __('Kanchanpur', 'invoicing')
1287 1287
     );
1288 1288
 
1289
-    return apply_filters( 'wpinv_nepal_states', $states );
1289
+    return apply_filters('wpinv_nepal_states', $states);
1290 1290
 }
1291 1291
 
1292 1292
 function wpinv_get_south_africa_states_list() {
1293 1293
     $states = array(
1294
-        'EC'  => __( 'Eastern Cape', 'invoicing' ),
1295
-        'FS'  => __( 'Free State', 'invoicing' ),
1296
-        'GP'  => __( 'Gauteng', 'invoicing' ),
1297
-        'KZN' => __( 'KwaZulu-Natal', 'invoicing' ),
1298
-        'LP'  => __( 'Limpopo', 'invoicing' ),
1299
-        'MP'  => __( 'Mpumalanga', 'invoicing' ),
1300
-        'NC'  => __( 'Northern Cape', 'invoicing' ),
1301
-        'NW'  => __( 'North West', 'invoicing' ),
1302
-        'WC'  => __( 'Western Cape', 'invoicing' )
1294
+        'EC'  => __('Eastern Cape', 'invoicing'),
1295
+        'FS'  => __('Free State', 'invoicing'),
1296
+        'GP'  => __('Gauteng', 'invoicing'),
1297
+        'KZN' => __('KwaZulu-Natal', 'invoicing'),
1298
+        'LP'  => __('Limpopo', 'invoicing'),
1299
+        'MP'  => __('Mpumalanga', 'invoicing'),
1300
+        'NC'  => __('Northern Cape', 'invoicing'),
1301
+        'NW'  => __('North West', 'invoicing'),
1302
+        'WC'  => __('Western Cape', 'invoicing')
1303 1303
     );
1304 1304
 
1305
-    return apply_filters( 'wpinv_south_africa_states', $states );
1305
+    return apply_filters('wpinv_south_africa_states', $states);
1306 1306
 }
1307 1307
 
1308 1308
 function wpinv_get_thailand_states_list() {
1309 1309
     $states = array(
1310
-        'TH-37' => __( 'Amnat Charoen (&#3629;&#3635;&#3609;&#3634;&#3592;&#3648;&#3592;&#3619;&#3636;&#3597;)', 'invoicing' ),
1311
-        'TH-15' => __( 'Ang Thong (&#3629;&#3656;&#3634;&#3591;&#3607;&#3629;&#3591;)', 'invoicing' ),
1312
-        'TH-14' => __( 'Ayutthaya (&#3614;&#3619;&#3632;&#3609;&#3588;&#3619;&#3624;&#3619;&#3637;&#3629;&#3618;&#3640;&#3608;&#3618;&#3634;)', 'invoicing' ),
1313
-        'TH-10' => __( 'Bangkok (&#3585;&#3619;&#3640;&#3591;&#3648;&#3607;&#3614;&#3617;&#3627;&#3634;&#3609;&#3588;&#3619;)', 'invoicing' ),
1314
-        'TH-38' => __( 'Bueng Kan (&#3610;&#3638;&#3591;&#3585;&#3634;&#3628;)', 'invoicing' ),
1315
-        'TH-31' => __( 'Buri Ram (&#3610;&#3640;&#3619;&#3637;&#3619;&#3633;&#3617;&#3618;&#3660;)', 'invoicing' ),
1316
-        'TH-24' => __( 'Chachoengsao (&#3593;&#3632;&#3648;&#3594;&#3636;&#3591;&#3648;&#3607;&#3619;&#3634;)', 'invoicing' ),
1317
-        'TH-18' => __( 'Chai Nat (&#3594;&#3633;&#3618;&#3609;&#3634;&#3607;)', 'invoicing' ),
1318
-        'TH-36' => __( 'Chaiyaphum (&#3594;&#3633;&#3618;&#3616;&#3641;&#3617;&#3636;)', 'invoicing' ),
1319
-        'TH-22' => __( 'Chanthaburi (&#3592;&#3633;&#3609;&#3607;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1320
-        'TH-50' => __( 'Chiang Mai (&#3648;&#3594;&#3637;&#3618;&#3591;&#3651;&#3627;&#3617;&#3656;)', 'invoicing' ),
1321
-        'TH-57' => __( 'Chiang Rai (&#3648;&#3594;&#3637;&#3618;&#3591;&#3619;&#3634;&#3618;)', 'invoicing' ),
1322
-        'TH-20' => __( 'Chonburi (&#3594;&#3621;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1323
-        'TH-86' => __( 'Chumphon (&#3594;&#3640;&#3617;&#3614;&#3619;)', 'invoicing' ),
1324
-        'TH-46' => __( 'Kalasin (&#3585;&#3634;&#3628;&#3626;&#3636;&#3609;&#3608;&#3640;&#3660;)', 'invoicing' ),
1325
-        'TH-62' => __( 'Kamphaeng Phet (&#3585;&#3635;&#3649;&#3614;&#3591;&#3648;&#3614;&#3594;&#3619;)', 'invoicing' ),
1326
-        'TH-71' => __( 'Kanchanaburi (&#3585;&#3634;&#3597;&#3592;&#3609;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1327
-        'TH-40' => __( 'Khon Kaen (&#3586;&#3629;&#3609;&#3649;&#3585;&#3656;&#3609;)', 'invoicing' ),
1328
-        'TH-81' => __( 'Krabi (&#3585;&#3619;&#3632;&#3610;&#3637;&#3656;)', 'invoicing' ),
1329
-        'TH-52' => __( 'Lampang (&#3621;&#3635;&#3611;&#3634;&#3591;)', 'invoicing' ),
1330
-        'TH-51' => __( 'Lamphun (&#3621;&#3635;&#3614;&#3641;&#3609;)', 'invoicing' ),
1331
-        'TH-42' => __( 'Loei (&#3648;&#3621;&#3618;)', 'invoicing' ),
1332
-        'TH-16' => __( 'Lopburi (&#3621;&#3614;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1333
-        'TH-58' => __( 'Mae Hong Son (&#3649;&#3617;&#3656;&#3630;&#3656;&#3629;&#3591;&#3626;&#3629;&#3609;)', 'invoicing' ),
1334
-        'TH-44' => __( 'Maha Sarakham (&#3617;&#3627;&#3634;&#3626;&#3634;&#3619;&#3588;&#3634;&#3617;)', 'invoicing' ),
1335
-        'TH-49' => __( 'Mukdahan (&#3617;&#3640;&#3585;&#3604;&#3634;&#3627;&#3634;&#3619;)', 'invoicing' ),
1336
-        'TH-26' => __( 'Nakhon Nayok (&#3609;&#3588;&#3619;&#3609;&#3634;&#3618;&#3585;)', 'invoicing' ),
1337
-        'TH-73' => __( 'Nakhon Pathom (&#3609;&#3588;&#3619;&#3611;&#3600;&#3617;)', 'invoicing' ),
1338
-        'TH-48' => __( 'Nakhon Phanom (&#3609;&#3588;&#3619;&#3614;&#3609;&#3617;)', 'invoicing' ),
1339
-        'TH-30' => __( 'Nakhon Ratchasima (&#3609;&#3588;&#3619;&#3619;&#3634;&#3594;&#3626;&#3637;&#3617;&#3634;)', 'invoicing' ),
1340
-        'TH-60' => __( 'Nakhon Sawan (&#3609;&#3588;&#3619;&#3626;&#3623;&#3619;&#3619;&#3588;&#3660;)', 'invoicing' ),
1341
-        'TH-80' => __( 'Nakhon Si Thammarat (&#3609;&#3588;&#3619;&#3624;&#3619;&#3637;&#3608;&#3619;&#3619;&#3617;&#3619;&#3634;&#3594;)', 'invoicing' ),
1342
-        'TH-55' => __( 'Nan (&#3609;&#3656;&#3634;&#3609;)', 'invoicing' ),
1343
-        'TH-96' => __( 'Narathiwat (&#3609;&#3619;&#3634;&#3608;&#3636;&#3623;&#3634;&#3626;)', 'invoicing' ),
1344
-        'TH-39' => __( 'Nong Bua Lam Phu (&#3627;&#3609;&#3629;&#3591;&#3610;&#3633;&#3623;&#3621;&#3635;&#3616;&#3641;)', 'invoicing' ),
1345
-        'TH-43' => __( 'Nong Khai (&#3627;&#3609;&#3629;&#3591;&#3588;&#3634;&#3618;)', 'invoicing' ),
1346
-        'TH-12' => __( 'Nonthaburi (&#3609;&#3609;&#3607;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1347
-        'TH-13' => __( 'Pathum Thani (&#3611;&#3607;&#3640;&#3617;&#3608;&#3634;&#3609;&#3637;)', 'invoicing' ),
1348
-        'TH-94' => __( 'Pattani (&#3611;&#3633;&#3605;&#3605;&#3634;&#3609;&#3637;)', 'invoicing' ),
1349
-        'TH-82' => __( 'Phang Nga (&#3614;&#3633;&#3591;&#3591;&#3634;)', 'invoicing' ),
1350
-        'TH-93' => __( 'Phatthalung (&#3614;&#3633;&#3607;&#3621;&#3640;&#3591;)', 'invoicing' ),
1351
-        'TH-56' => __( 'Phayao (&#3614;&#3632;&#3648;&#3618;&#3634;)', 'invoicing' ),
1352
-        'TH-67' => __( 'Phetchabun (&#3648;&#3614;&#3594;&#3619;&#3610;&#3641;&#3619;&#3603;&#3660;)', 'invoicing' ),
1353
-        'TH-76' => __( 'Phetchaburi (&#3648;&#3614;&#3594;&#3619;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1354
-        'TH-66' => __( 'Phichit (&#3614;&#3636;&#3592;&#3636;&#3605;&#3619;)', 'invoicing' ),
1355
-        'TH-65' => __( 'Phitsanulok (&#3614;&#3636;&#3625;&#3603;&#3640;&#3650;&#3621;&#3585;)', 'invoicing' ),
1356
-        'TH-54' => __( 'Phrae (&#3649;&#3614;&#3619;&#3656;)', 'invoicing' ),
1357
-        'TH-83' => __( 'Phuket (&#3616;&#3641;&#3648;&#3585;&#3655;&#3605;)', 'invoicing' ),
1358
-        'TH-25' => __( 'Prachin Buri (&#3611;&#3619;&#3634;&#3592;&#3637;&#3609;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1359
-        'TH-77' => __( 'Prachuap Khiri Khan (&#3611;&#3619;&#3632;&#3592;&#3623;&#3610;&#3588;&#3637;&#3619;&#3637;&#3586;&#3633;&#3609;&#3608;&#3660;)', 'invoicing' ),
1360
-        'TH-85' => __( 'Ranong (&#3619;&#3632;&#3609;&#3629;&#3591;)', 'invoicing' ),
1361
-        'TH-70' => __( 'Ratchaburi (&#3619;&#3634;&#3594;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1362
-        'TH-21' => __( 'Rayong (&#3619;&#3632;&#3618;&#3629;&#3591;)', 'invoicing' ),
1363
-        'TH-45' => __( 'Roi Et (&#3619;&#3657;&#3629;&#3618;&#3648;&#3629;&#3655;&#3604;)', 'invoicing' ),
1364
-        'TH-27' => __( 'Sa Kaeo (&#3626;&#3619;&#3632;&#3649;&#3585;&#3657;&#3623;)', 'invoicing' ),
1365
-        'TH-47' => __( 'Sakon Nakhon (&#3626;&#3585;&#3621;&#3609;&#3588;&#3619;)', 'invoicing' ),
1366
-        'TH-11' => __( 'Samut Prakan (&#3626;&#3617;&#3640;&#3607;&#3619;&#3611;&#3619;&#3634;&#3585;&#3634;&#3619;)', 'invoicing' ),
1367
-        'TH-74' => __( 'Samut Sakhon (&#3626;&#3617;&#3640;&#3607;&#3619;&#3626;&#3634;&#3588;&#3619;)', 'invoicing' ),
1368
-        'TH-75' => __( 'Samut Songkhram (&#3626;&#3617;&#3640;&#3607;&#3619;&#3626;&#3591;&#3588;&#3619;&#3634;&#3617;)', 'invoicing' ),
1369
-        'TH-19' => __( 'Saraburi (&#3626;&#3619;&#3632;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1370
-        'TH-91' => __( 'Satun (&#3626;&#3605;&#3641;&#3621;)', 'invoicing' ),
1371
-        'TH-17' => __( 'Sing Buri (&#3626;&#3636;&#3591;&#3627;&#3660;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1372
-        'TH-33' => __( 'Sisaket (&#3624;&#3619;&#3637;&#3626;&#3632;&#3648;&#3585;&#3625;)', 'invoicing' ),
1373
-        'TH-90' => __( 'Songkhla (&#3626;&#3591;&#3586;&#3621;&#3634;)', 'invoicing' ),
1374
-        'TH-64' => __( 'Sukhothai (&#3626;&#3640;&#3650;&#3586;&#3607;&#3633;&#3618;)', 'invoicing' ),
1375
-        'TH-72' => __( 'Suphan Buri (&#3626;&#3640;&#3614;&#3619;&#3619;&#3603;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1376
-        'TH-84' => __( 'Surat Thani (&#3626;&#3640;&#3619;&#3634;&#3625;&#3598;&#3619;&#3660;&#3608;&#3634;&#3609;&#3637;)', 'invoicing' ),
1377
-        'TH-32' => __( 'Surin (&#3626;&#3640;&#3619;&#3636;&#3609;&#3607;&#3619;&#3660;)', 'invoicing' ),
1378
-        'TH-63' => __( 'Tak (&#3605;&#3634;&#3585;)', 'invoicing' ),
1379
-        'TH-92' => __( 'Trang (&#3605;&#3619;&#3633;&#3591;)', 'invoicing' ),
1380
-        'TH-23' => __( 'Trat (&#3605;&#3619;&#3634;&#3604;)', 'invoicing' ),
1381
-        'TH-34' => __( 'Ubon Ratchathani (&#3629;&#3640;&#3610;&#3621;&#3619;&#3634;&#3594;&#3608;&#3634;&#3609;&#3637;)', 'invoicing' ),
1382
-        'TH-41' => __( 'Udon Thani (&#3629;&#3640;&#3604;&#3619;&#3608;&#3634;&#3609;&#3637;)', 'invoicing' ),
1383
-        'TH-61' => __( 'Uthai Thani (&#3629;&#3640;&#3607;&#3633;&#3618;&#3608;&#3634;&#3609;&#3637;)', 'invoicing' ),
1384
-        'TH-53' => __( 'Uttaradit (&#3629;&#3640;&#3605;&#3619;&#3604;&#3636;&#3605;&#3606;&#3660;)', 'invoicing' ),
1385
-        'TH-95' => __( 'Yala (&#3618;&#3632;&#3621;&#3634;)', 'invoicing' ),
1386
-        'TH-35' => __( 'Yasothon (&#3618;&#3650;&#3626;&#3608;&#3619;)', 'invoicing' )
1310
+        'TH-37' => __('Amnat Charoen (&#3629;&#3635;&#3609;&#3634;&#3592;&#3648;&#3592;&#3619;&#3636;&#3597;)', 'invoicing'),
1311
+        'TH-15' => __('Ang Thong (&#3629;&#3656;&#3634;&#3591;&#3607;&#3629;&#3591;)', 'invoicing'),
1312
+        'TH-14' => __('Ayutthaya (&#3614;&#3619;&#3632;&#3609;&#3588;&#3619;&#3624;&#3619;&#3637;&#3629;&#3618;&#3640;&#3608;&#3618;&#3634;)', 'invoicing'),
1313
+        'TH-10' => __('Bangkok (&#3585;&#3619;&#3640;&#3591;&#3648;&#3607;&#3614;&#3617;&#3627;&#3634;&#3609;&#3588;&#3619;)', 'invoicing'),
1314
+        'TH-38' => __('Bueng Kan (&#3610;&#3638;&#3591;&#3585;&#3634;&#3628;)', 'invoicing'),
1315
+        'TH-31' => __('Buri Ram (&#3610;&#3640;&#3619;&#3637;&#3619;&#3633;&#3617;&#3618;&#3660;)', 'invoicing'),
1316
+        'TH-24' => __('Chachoengsao (&#3593;&#3632;&#3648;&#3594;&#3636;&#3591;&#3648;&#3607;&#3619;&#3634;)', 'invoicing'),
1317
+        'TH-18' => __('Chai Nat (&#3594;&#3633;&#3618;&#3609;&#3634;&#3607;)', 'invoicing'),
1318
+        'TH-36' => __('Chaiyaphum (&#3594;&#3633;&#3618;&#3616;&#3641;&#3617;&#3636;)', 'invoicing'),
1319
+        'TH-22' => __('Chanthaburi (&#3592;&#3633;&#3609;&#3607;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1320
+        'TH-50' => __('Chiang Mai (&#3648;&#3594;&#3637;&#3618;&#3591;&#3651;&#3627;&#3617;&#3656;)', 'invoicing'),
1321
+        'TH-57' => __('Chiang Rai (&#3648;&#3594;&#3637;&#3618;&#3591;&#3619;&#3634;&#3618;)', 'invoicing'),
1322
+        'TH-20' => __('Chonburi (&#3594;&#3621;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1323
+        'TH-86' => __('Chumphon (&#3594;&#3640;&#3617;&#3614;&#3619;)', 'invoicing'),
1324
+        'TH-46' => __('Kalasin (&#3585;&#3634;&#3628;&#3626;&#3636;&#3609;&#3608;&#3640;&#3660;)', 'invoicing'),
1325
+        'TH-62' => __('Kamphaeng Phet (&#3585;&#3635;&#3649;&#3614;&#3591;&#3648;&#3614;&#3594;&#3619;)', 'invoicing'),
1326
+        'TH-71' => __('Kanchanaburi (&#3585;&#3634;&#3597;&#3592;&#3609;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1327
+        'TH-40' => __('Khon Kaen (&#3586;&#3629;&#3609;&#3649;&#3585;&#3656;&#3609;)', 'invoicing'),
1328
+        'TH-81' => __('Krabi (&#3585;&#3619;&#3632;&#3610;&#3637;&#3656;)', 'invoicing'),
1329
+        'TH-52' => __('Lampang (&#3621;&#3635;&#3611;&#3634;&#3591;)', 'invoicing'),
1330
+        'TH-51' => __('Lamphun (&#3621;&#3635;&#3614;&#3641;&#3609;)', 'invoicing'),
1331
+        'TH-42' => __('Loei (&#3648;&#3621;&#3618;)', 'invoicing'),
1332
+        'TH-16' => __('Lopburi (&#3621;&#3614;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1333
+        'TH-58' => __('Mae Hong Son (&#3649;&#3617;&#3656;&#3630;&#3656;&#3629;&#3591;&#3626;&#3629;&#3609;)', 'invoicing'),
1334
+        'TH-44' => __('Maha Sarakham (&#3617;&#3627;&#3634;&#3626;&#3634;&#3619;&#3588;&#3634;&#3617;)', 'invoicing'),
1335
+        'TH-49' => __('Mukdahan (&#3617;&#3640;&#3585;&#3604;&#3634;&#3627;&#3634;&#3619;)', 'invoicing'),
1336
+        'TH-26' => __('Nakhon Nayok (&#3609;&#3588;&#3619;&#3609;&#3634;&#3618;&#3585;)', 'invoicing'),
1337
+        'TH-73' => __('Nakhon Pathom (&#3609;&#3588;&#3619;&#3611;&#3600;&#3617;)', 'invoicing'),
1338
+        'TH-48' => __('Nakhon Phanom (&#3609;&#3588;&#3619;&#3614;&#3609;&#3617;)', 'invoicing'),
1339
+        'TH-30' => __('Nakhon Ratchasima (&#3609;&#3588;&#3619;&#3619;&#3634;&#3594;&#3626;&#3637;&#3617;&#3634;)', 'invoicing'),
1340
+        'TH-60' => __('Nakhon Sawan (&#3609;&#3588;&#3619;&#3626;&#3623;&#3619;&#3619;&#3588;&#3660;)', 'invoicing'),
1341
+        'TH-80' => __('Nakhon Si Thammarat (&#3609;&#3588;&#3619;&#3624;&#3619;&#3637;&#3608;&#3619;&#3619;&#3617;&#3619;&#3634;&#3594;)', 'invoicing'),
1342
+        'TH-55' => __('Nan (&#3609;&#3656;&#3634;&#3609;)', 'invoicing'),
1343
+        'TH-96' => __('Narathiwat (&#3609;&#3619;&#3634;&#3608;&#3636;&#3623;&#3634;&#3626;)', 'invoicing'),
1344
+        'TH-39' => __('Nong Bua Lam Phu (&#3627;&#3609;&#3629;&#3591;&#3610;&#3633;&#3623;&#3621;&#3635;&#3616;&#3641;)', 'invoicing'),
1345
+        'TH-43' => __('Nong Khai (&#3627;&#3609;&#3629;&#3591;&#3588;&#3634;&#3618;)', 'invoicing'),
1346
+        'TH-12' => __('Nonthaburi (&#3609;&#3609;&#3607;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1347
+        'TH-13' => __('Pathum Thani (&#3611;&#3607;&#3640;&#3617;&#3608;&#3634;&#3609;&#3637;)', 'invoicing'),
1348
+        'TH-94' => __('Pattani (&#3611;&#3633;&#3605;&#3605;&#3634;&#3609;&#3637;)', 'invoicing'),
1349
+        'TH-82' => __('Phang Nga (&#3614;&#3633;&#3591;&#3591;&#3634;)', 'invoicing'),
1350
+        'TH-93' => __('Phatthalung (&#3614;&#3633;&#3607;&#3621;&#3640;&#3591;)', 'invoicing'),
1351
+        'TH-56' => __('Phayao (&#3614;&#3632;&#3648;&#3618;&#3634;)', 'invoicing'),
1352
+        'TH-67' => __('Phetchabun (&#3648;&#3614;&#3594;&#3619;&#3610;&#3641;&#3619;&#3603;&#3660;)', 'invoicing'),
1353
+        'TH-76' => __('Phetchaburi (&#3648;&#3614;&#3594;&#3619;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1354
+        'TH-66' => __('Phichit (&#3614;&#3636;&#3592;&#3636;&#3605;&#3619;)', 'invoicing'),
1355
+        'TH-65' => __('Phitsanulok (&#3614;&#3636;&#3625;&#3603;&#3640;&#3650;&#3621;&#3585;)', 'invoicing'),
1356
+        'TH-54' => __('Phrae (&#3649;&#3614;&#3619;&#3656;)', 'invoicing'),
1357
+        'TH-83' => __('Phuket (&#3616;&#3641;&#3648;&#3585;&#3655;&#3605;)', 'invoicing'),
1358
+        'TH-25' => __('Prachin Buri (&#3611;&#3619;&#3634;&#3592;&#3637;&#3609;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1359
+        'TH-77' => __('Prachuap Khiri Khan (&#3611;&#3619;&#3632;&#3592;&#3623;&#3610;&#3588;&#3637;&#3619;&#3637;&#3586;&#3633;&#3609;&#3608;&#3660;)', 'invoicing'),
1360
+        'TH-85' => __('Ranong (&#3619;&#3632;&#3609;&#3629;&#3591;)', 'invoicing'),
1361
+        'TH-70' => __('Ratchaburi (&#3619;&#3634;&#3594;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1362
+        'TH-21' => __('Rayong (&#3619;&#3632;&#3618;&#3629;&#3591;)', 'invoicing'),
1363
+        'TH-45' => __('Roi Et (&#3619;&#3657;&#3629;&#3618;&#3648;&#3629;&#3655;&#3604;)', 'invoicing'),
1364
+        'TH-27' => __('Sa Kaeo (&#3626;&#3619;&#3632;&#3649;&#3585;&#3657;&#3623;)', 'invoicing'),
1365
+        'TH-47' => __('Sakon Nakhon (&#3626;&#3585;&#3621;&#3609;&#3588;&#3619;)', 'invoicing'),
1366
+        'TH-11' => __('Samut Prakan (&#3626;&#3617;&#3640;&#3607;&#3619;&#3611;&#3619;&#3634;&#3585;&#3634;&#3619;)', 'invoicing'),
1367
+        'TH-74' => __('Samut Sakhon (&#3626;&#3617;&#3640;&#3607;&#3619;&#3626;&#3634;&#3588;&#3619;)', 'invoicing'),
1368
+        'TH-75' => __('Samut Songkhram (&#3626;&#3617;&#3640;&#3607;&#3619;&#3626;&#3591;&#3588;&#3619;&#3634;&#3617;)', 'invoicing'),
1369
+        'TH-19' => __('Saraburi (&#3626;&#3619;&#3632;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1370
+        'TH-91' => __('Satun (&#3626;&#3605;&#3641;&#3621;)', 'invoicing'),
1371
+        'TH-17' => __('Sing Buri (&#3626;&#3636;&#3591;&#3627;&#3660;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1372
+        'TH-33' => __('Sisaket (&#3624;&#3619;&#3637;&#3626;&#3632;&#3648;&#3585;&#3625;)', 'invoicing'),
1373
+        'TH-90' => __('Songkhla (&#3626;&#3591;&#3586;&#3621;&#3634;)', 'invoicing'),
1374
+        'TH-64' => __('Sukhothai (&#3626;&#3640;&#3650;&#3586;&#3607;&#3633;&#3618;)', 'invoicing'),
1375
+        'TH-72' => __('Suphan Buri (&#3626;&#3640;&#3614;&#3619;&#3619;&#3603;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1376
+        'TH-84' => __('Surat Thani (&#3626;&#3640;&#3619;&#3634;&#3625;&#3598;&#3619;&#3660;&#3608;&#3634;&#3609;&#3637;)', 'invoicing'),
1377
+        'TH-32' => __('Surin (&#3626;&#3640;&#3619;&#3636;&#3609;&#3607;&#3619;&#3660;)', 'invoicing'),
1378
+        'TH-63' => __('Tak (&#3605;&#3634;&#3585;)', 'invoicing'),
1379
+        'TH-92' => __('Trang (&#3605;&#3619;&#3633;&#3591;)', 'invoicing'),
1380
+        'TH-23' => __('Trat (&#3605;&#3619;&#3634;&#3604;)', 'invoicing'),
1381
+        'TH-34' => __('Ubon Ratchathani (&#3629;&#3640;&#3610;&#3621;&#3619;&#3634;&#3594;&#3608;&#3634;&#3609;&#3637;)', 'invoicing'),
1382
+        'TH-41' => __('Udon Thani (&#3629;&#3640;&#3604;&#3619;&#3608;&#3634;&#3609;&#3637;)', 'invoicing'),
1383
+        'TH-61' => __('Uthai Thani (&#3629;&#3640;&#3607;&#3633;&#3618;&#3608;&#3634;&#3609;&#3637;)', 'invoicing'),
1384
+        'TH-53' => __('Uttaradit (&#3629;&#3640;&#3605;&#3619;&#3604;&#3636;&#3605;&#3606;&#3660;)', 'invoicing'),
1385
+        'TH-95' => __('Yala (&#3618;&#3632;&#3621;&#3634;)', 'invoicing'),
1386
+        'TH-35' => __('Yasothon (&#3618;&#3650;&#3626;&#3608;&#3619;)', 'invoicing')
1387 1387
     );
1388 1388
 
1389
-    return apply_filters( 'wpinv_thailand_states', $states );
1389
+    return apply_filters('wpinv_thailand_states', $states);
1390 1390
 }
1391 1391
 
1392 1392
 function wpinv_get_turkey_states_list() {
1393 1393
     $states = array(
1394
-        'TR01' => __( 'Adana', 'invoicing' ),
1395
-        'TR02' => __( 'Ad&#305;yaman', 'invoicing' ),
1396
-        'TR03' => __( 'Afyon', 'invoicing' ),
1397
-        'TR04' => __( 'A&#287;r&#305;', 'invoicing' ),
1398
-        'TR05' => __( 'Amasya', 'invoicing' ),
1399
-        'TR06' => __( 'Ankara', 'invoicing' ),
1400
-        'TR07' => __( 'Antalya', 'invoicing' ),
1401
-        'TR08' => __( 'Artvin', 'invoicing' ),
1402
-        'TR09' => __( 'Ayd&#305;n', 'invoicing' ),
1403
-        'TR10' => __( 'Bal&#305;kesir', 'invoicing' ),
1404
-        'TR11' => __( 'Bilecik', 'invoicing' ),
1405
-        'TR12' => __( 'Bing&#246;l', 'invoicing' ),
1406
-        'TR13' => __( 'Bitlis', 'invoicing' ),
1407
-        'TR14' => __( 'Bolu', 'invoicing' ),
1408
-        'TR15' => __( 'Burdur', 'invoicing' ),
1409
-        'TR16' => __( 'Bursa', 'invoicing' ),
1410
-        'TR17' => __( '&#199;anakkale', 'invoicing' ),
1411
-        'TR18' => __( '&#199;ank&#305;kesir', 'invoicing' ),
1412
-        'TR19' => __( '&#199;orum', 'invoicing' ),
1413
-        'TR20' => __( 'Denizli', 'invoicing' ),
1414
-        'TR21' => __( 'Diyarbak&#305;r', 'invoicing' ),
1415
-        'TR22' => __( 'Edirne', 'invoicing' ),
1416
-        'TR23' => __( 'Elaz&#305;&#287;', 'invoicing' ),
1417
-        'TR24' => __( 'Erzincan', 'invoicing' ),
1418
-        'TR25' => __( 'Erzurum', 'invoicing' ),
1419
-        'TR26' => __( 'Eski&#351;ehir', 'invoicing' ),
1420
-        'TR27' => __( 'Gaziantep', 'invoicing' ),
1421
-        'TR28' => __( 'Giresun', 'invoicing' ),
1422
-        'TR29' => __( 'G&#252;m&#252;&#351;hane', 'invoicing' ),
1423
-        'TR30' => __( 'Hakkari', 'invoicing' ),
1424
-        'TR31' => __( 'Hatay', 'invoicing' ),
1425
-        'TR32' => __( 'Isparta', 'invoicing' ),
1426
-        'TR33' => __( '&#304;&#231;el', 'invoicing' ),
1427
-        'TR34' => __( '&#304;stanbul', 'invoicing' ),
1428
-        'TR35' => __( '&#304;zmir', 'invoicing' ),
1429
-        'TR36' => __( 'Kars', 'invoicing' ),
1430
-        'TR37' => __( 'Kastamonu', 'invoicing' ),
1431
-        'TR38' => __( 'Kayseri', 'invoicing' ),
1432
-        'TR39' => __( 'K&#305;rklareli', 'invoicing' ),
1433
-        'TR40' => __( 'K&#305;r&#351;ehir', 'invoicing' ),
1434
-        'TR41' => __( 'Kocaeli', 'invoicing' ),
1435
-        'TR42' => __( 'Konya', 'invoicing' ),
1436
-        'TR43' => __( 'K&#252;tahya', 'invoicing' ),
1437
-        'TR44' => __( 'Malatya', 'invoicing' ),
1438
-        'TR45' => __( 'Manisa', 'invoicing' ),
1439
-        'TR46' => __( 'Kahramanmara&#351;', 'invoicing' ),
1440
-        'TR47' => __( 'Mardin', 'invoicing' ),
1441
-        'TR48' => __( 'Mu&#287;la', 'invoicing' ),
1442
-        'TR49' => __( 'Mu&#351;', 'invoicing' ),
1443
-        'TR50' => __( 'Nev&#351;ehir', 'invoicing' ),
1444
-        'TR51' => __( 'Ni&#287;de', 'invoicing' ),
1445
-        'TR52' => __( 'Ordu', 'invoicing' ),
1446
-        'TR53' => __( 'Rize', 'invoicing' ),
1447
-        'TR54' => __( 'Sakarya', 'invoicing' ),
1448
-        'TR55' => __( 'Samsun', 'invoicing' ),
1449
-        'TR56' => __( 'Siirt', 'invoicing' ),
1450
-        'TR57' => __( 'Sinop', 'invoicing' ),
1451
-        'TR58' => __( 'Sivas', 'invoicing' ),
1452
-        'TR59' => __( 'Tekirda&#287;', 'invoicing' ),
1453
-        'TR60' => __( 'Tokat', 'invoicing' ),
1454
-        'TR61' => __( 'Trabzon', 'invoicing' ),
1455
-        'TR62' => __( 'Tunceli', 'invoicing' ),
1456
-        'TR63' => __( '&#350;anl&#305;urfa', 'invoicing' ),
1457
-        'TR64' => __( 'U&#351;ak', 'invoicing' ),
1458
-        'TR65' => __( 'Van', 'invoicing' ),
1459
-        'TR66' => __( 'Yozgat', 'invoicing' ),
1460
-        'TR67' => __( 'Zonguldak', 'invoicing' ),
1461
-        'TR68' => __( 'Aksaray', 'invoicing' ),
1462
-        'TR69' => __( 'Bayburt', 'invoicing' ),
1463
-        'TR70' => __( 'Karaman', 'invoicing' ),
1464
-        'TR71' => __( 'K&#305;r&#305;kkale', 'invoicing' ),
1465
-        'TR72' => __( 'Batman', 'invoicing' ),
1466
-        'TR73' => __( '&#350;&#305;rnak', 'invoicing' ),
1467
-        'TR74' => __( 'Bart&#305;n', 'invoicing' ),
1468
-        'TR75' => __( 'Ardahan', 'invoicing' ),
1469
-        'TR76' => __( 'I&#287;d&#305;r', 'invoicing' ),
1470
-        'TR77' => __( 'Yalova', 'invoicing' ),
1471
-        'TR78' => __( 'Karab&#252;k', 'invoicing' ),
1472
-        'TR79' => __( 'Kilis', 'invoicing' ),
1473
-        'TR80' => __( 'Osmaniye', 'invoicing' ),
1474
-        'TR81' => __( 'D&#252;zce', 'invoicing' )
1394
+        'TR01' => __('Adana', 'invoicing'),
1395
+        'TR02' => __('Ad&#305;yaman', 'invoicing'),
1396
+        'TR03' => __('Afyon', 'invoicing'),
1397
+        'TR04' => __('A&#287;r&#305;', 'invoicing'),
1398
+        'TR05' => __('Amasya', 'invoicing'),
1399
+        'TR06' => __('Ankara', 'invoicing'),
1400
+        'TR07' => __('Antalya', 'invoicing'),
1401
+        'TR08' => __('Artvin', 'invoicing'),
1402
+        'TR09' => __('Ayd&#305;n', 'invoicing'),
1403
+        'TR10' => __('Bal&#305;kesir', 'invoicing'),
1404
+        'TR11' => __('Bilecik', 'invoicing'),
1405
+        'TR12' => __('Bing&#246;l', 'invoicing'),
1406
+        'TR13' => __('Bitlis', 'invoicing'),
1407
+        'TR14' => __('Bolu', 'invoicing'),
1408
+        'TR15' => __('Burdur', 'invoicing'),
1409
+        'TR16' => __('Bursa', 'invoicing'),
1410
+        'TR17' => __('&#199;anakkale', 'invoicing'),
1411
+        'TR18' => __('&#199;ank&#305;kesir', 'invoicing'),
1412
+        'TR19' => __('&#199;orum', 'invoicing'),
1413
+        'TR20' => __('Denizli', 'invoicing'),
1414
+        'TR21' => __('Diyarbak&#305;r', 'invoicing'),
1415
+        'TR22' => __('Edirne', 'invoicing'),
1416
+        'TR23' => __('Elaz&#305;&#287;', 'invoicing'),
1417
+        'TR24' => __('Erzincan', 'invoicing'),
1418
+        'TR25' => __('Erzurum', 'invoicing'),
1419
+        'TR26' => __('Eski&#351;ehir', 'invoicing'),
1420
+        'TR27' => __('Gaziantep', 'invoicing'),
1421
+        'TR28' => __('Giresun', 'invoicing'),
1422
+        'TR29' => __('G&#252;m&#252;&#351;hane', 'invoicing'),
1423
+        'TR30' => __('Hakkari', 'invoicing'),
1424
+        'TR31' => __('Hatay', 'invoicing'),
1425
+        'TR32' => __('Isparta', 'invoicing'),
1426
+        'TR33' => __('&#304;&#231;el', 'invoicing'),
1427
+        'TR34' => __('&#304;stanbul', 'invoicing'),
1428
+        'TR35' => __('&#304;zmir', 'invoicing'),
1429
+        'TR36' => __('Kars', 'invoicing'),
1430
+        'TR37' => __('Kastamonu', 'invoicing'),
1431
+        'TR38' => __('Kayseri', 'invoicing'),
1432
+        'TR39' => __('K&#305;rklareli', 'invoicing'),
1433
+        'TR40' => __('K&#305;r&#351;ehir', 'invoicing'),
1434
+        'TR41' => __('Kocaeli', 'invoicing'),
1435
+        'TR42' => __('Konya', 'invoicing'),
1436
+        'TR43' => __('K&#252;tahya', 'invoicing'),
1437
+        'TR44' => __('Malatya', 'invoicing'),
1438
+        'TR45' => __('Manisa', 'invoicing'),
1439
+        'TR46' => __('Kahramanmara&#351;', 'invoicing'),
1440
+        'TR47' => __('Mardin', 'invoicing'),
1441
+        'TR48' => __('Mu&#287;la', 'invoicing'),
1442
+        'TR49' => __('Mu&#351;', 'invoicing'),
1443
+        'TR50' => __('Nev&#351;ehir', 'invoicing'),
1444
+        'TR51' => __('Ni&#287;de', 'invoicing'),
1445
+        'TR52' => __('Ordu', 'invoicing'),
1446
+        'TR53' => __('Rize', 'invoicing'),
1447
+        'TR54' => __('Sakarya', 'invoicing'),
1448
+        'TR55' => __('Samsun', 'invoicing'),
1449
+        'TR56' => __('Siirt', 'invoicing'),
1450
+        'TR57' => __('Sinop', 'invoicing'),
1451
+        'TR58' => __('Sivas', 'invoicing'),
1452
+        'TR59' => __('Tekirda&#287;', 'invoicing'),
1453
+        'TR60' => __('Tokat', 'invoicing'),
1454
+        'TR61' => __('Trabzon', 'invoicing'),
1455
+        'TR62' => __('Tunceli', 'invoicing'),
1456
+        'TR63' => __('&#350;anl&#305;urfa', 'invoicing'),
1457
+        'TR64' => __('U&#351;ak', 'invoicing'),
1458
+        'TR65' => __('Van', 'invoicing'),
1459
+        'TR66' => __('Yozgat', 'invoicing'),
1460
+        'TR67' => __('Zonguldak', 'invoicing'),
1461
+        'TR68' => __('Aksaray', 'invoicing'),
1462
+        'TR69' => __('Bayburt', 'invoicing'),
1463
+        'TR70' => __('Karaman', 'invoicing'),
1464
+        'TR71' => __('K&#305;r&#305;kkale', 'invoicing'),
1465
+        'TR72' => __('Batman', 'invoicing'),
1466
+        'TR73' => __('&#350;&#305;rnak', 'invoicing'),
1467
+        'TR74' => __('Bart&#305;n', 'invoicing'),
1468
+        'TR75' => __('Ardahan', 'invoicing'),
1469
+        'TR76' => __('I&#287;d&#305;r', 'invoicing'),
1470
+        'TR77' => __('Yalova', 'invoicing'),
1471
+        'TR78' => __('Karab&#252;k', 'invoicing'),
1472
+        'TR79' => __('Kilis', 'invoicing'),
1473
+        'TR80' => __('Osmaniye', 'invoicing'),
1474
+        'TR81' => __('D&#252;zce', 'invoicing')
1475 1475
     );
1476 1476
 
1477
-    return apply_filters( 'wpinv_turkey_states', $states );
1477
+    return apply_filters('wpinv_turkey_states', $states);
1478 1478
 }
1479 1479
 
1480 1480
 function wpinv_get_spain_states_list() {
1481 1481
     $states = array(
1482
-        'C'  => __( 'A Coru&ntilde;a', 'invoicing' ),
1483
-        'VI' => __( 'Araba', 'invoicing' ),
1484
-        'AB' => __( 'Albacete', 'invoicing' ),
1485
-        'A'  => __( 'Alicante', 'invoicing' ),
1486
-        'AL' => __( 'Almer&iacute;a', 'invoicing' ),
1487
-        'O'  => __( 'Asturias', 'invoicing' ),
1488
-        'AV' => __( '&Aacute;vila', 'invoicing' ),
1489
-        'BA' => __( 'Badajoz', 'invoicing' ),
1490
-        'PM' => __( 'Baleares', 'invoicing' ),
1491
-        'B'  => __( 'Barcelona', 'invoicing' ),
1492
-        'BU' => __( 'Burgos', 'invoicing' ),
1493
-        'CC' => __( 'C&aacute;ceres', 'invoicing' ),
1494
-        'CA' => __( 'C&aacute;diz', 'invoicing' ),
1495
-        'S'  => __( 'Cantabria', 'invoicing' ),
1496
-        'CS' => __( 'Castell&oacute;n', 'invoicing' ),
1497
-        'CE' => __( 'Ceuta', 'invoicing' ),
1498
-        'CR' => __( 'Ciudad Real', 'invoicing' ),
1499
-        'CO' => __( 'C&oacute;rdoba', 'invoicing' ),
1500
-        'CU' => __( 'Cuenca', 'invoicing' ),
1501
-        'GI' => __( 'Girona', 'invoicing' ),
1502
-        'GR' => __( 'Granada', 'invoicing' ),
1503
-        'GU' => __( 'Guadalajara', 'invoicing' ),
1504
-        'SS' => __( 'Gipuzkoa', 'invoicing' ),
1505
-        'H'  => __( 'Huelva', 'invoicing' ),
1506
-        'HU' => __( 'Huesca', 'invoicing' ),
1507
-        'J'  => __( 'Ja&eacute;n', 'invoicing' ),
1508
-        'LO' => __( 'La Rioja', 'invoicing' ),
1509
-        'GC' => __( 'Las Palmas', 'invoicing' ),
1510
-        'LE' => __( 'Le&oacute;n', 'invoicing' ),
1511
-        'L'  => __( 'Lleida', 'invoicing' ),
1512
-        'LU' => __( 'Lugo', 'invoicing' ),
1513
-        'M'  => __( 'Madrid', 'invoicing' ),
1514
-        'MA' => __( 'M&aacute;laga', 'invoicing' ),
1515
-        'ML' => __( 'Melilla', 'invoicing' ),
1516
-        'MU' => __( 'Murcia', 'invoicing' ),
1517
-        'NA' => __( 'Navarra', 'invoicing' ),
1518
-        'OR' => __( 'Ourense', 'invoicing' ),
1519
-        'P'  => __( 'Palencia', 'invoicing' ),
1520
-        'PO' => __( 'Pontevedra', 'invoicing' ),
1521
-        'SA' => __( 'Salamanca', 'invoicing' ),
1522
-        'TF' => __( 'Santa Cruz de Tenerife', 'invoicing' ),
1523
-        'SG' => __( 'Segovia', 'invoicing' ),
1524
-        'SE' => __( 'Sevilla', 'invoicing' ),
1525
-        'SO' => __( 'Soria', 'invoicing' ),
1526
-        'T'  => __( 'Tarragona', 'invoicing' ),
1527
-        'TE' => __( 'Teruel', 'invoicing' ),
1528
-        'TO' => __( 'Toledo', 'invoicing' ),
1529
-        'V'  => __( 'Valencia', 'invoicing' ),
1530
-        'VA' => __( 'Valladolid', 'invoicing' ),
1531
-        'BI' => __( 'Bizkaia', 'invoicing' ),
1532
-        'ZA' => __( 'Zamora', 'invoicing' ),
1533
-        'Z'  => __( 'Zaragoza', 'invoicing' )
1482
+        'C'  => __('A Coru&ntilde;a', 'invoicing'),
1483
+        'VI' => __('Araba', 'invoicing'),
1484
+        'AB' => __('Albacete', 'invoicing'),
1485
+        'A'  => __('Alicante', 'invoicing'),
1486
+        'AL' => __('Almer&iacute;a', 'invoicing'),
1487
+        'O'  => __('Asturias', 'invoicing'),
1488
+        'AV' => __('&Aacute;vila', 'invoicing'),
1489
+        'BA' => __('Badajoz', 'invoicing'),
1490
+        'PM' => __('Baleares', 'invoicing'),
1491
+        'B'  => __('Barcelona', 'invoicing'),
1492
+        'BU' => __('Burgos', 'invoicing'),
1493
+        'CC' => __('C&aacute;ceres', 'invoicing'),
1494
+        'CA' => __('C&aacute;diz', 'invoicing'),
1495
+        'S'  => __('Cantabria', 'invoicing'),
1496
+        'CS' => __('Castell&oacute;n', 'invoicing'),
1497
+        'CE' => __('Ceuta', 'invoicing'),
1498
+        'CR' => __('Ciudad Real', 'invoicing'),
1499
+        'CO' => __('C&oacute;rdoba', 'invoicing'),
1500
+        'CU' => __('Cuenca', 'invoicing'),
1501
+        'GI' => __('Girona', 'invoicing'),
1502
+        'GR' => __('Granada', 'invoicing'),
1503
+        'GU' => __('Guadalajara', 'invoicing'),
1504
+        'SS' => __('Gipuzkoa', 'invoicing'),
1505
+        'H'  => __('Huelva', 'invoicing'),
1506
+        'HU' => __('Huesca', 'invoicing'),
1507
+        'J'  => __('Ja&eacute;n', 'invoicing'),
1508
+        'LO' => __('La Rioja', 'invoicing'),
1509
+        'GC' => __('Las Palmas', 'invoicing'),
1510
+        'LE' => __('Le&oacute;n', 'invoicing'),
1511
+        'L'  => __('Lleida', 'invoicing'),
1512
+        'LU' => __('Lugo', 'invoicing'),
1513
+        'M'  => __('Madrid', 'invoicing'),
1514
+        'MA' => __('M&aacute;laga', 'invoicing'),
1515
+        'ML' => __('Melilla', 'invoicing'),
1516
+        'MU' => __('Murcia', 'invoicing'),
1517
+        'NA' => __('Navarra', 'invoicing'),
1518
+        'OR' => __('Ourense', 'invoicing'),
1519
+        'P'  => __('Palencia', 'invoicing'),
1520
+        'PO' => __('Pontevedra', 'invoicing'),
1521
+        'SA' => __('Salamanca', 'invoicing'),
1522
+        'TF' => __('Santa Cruz de Tenerife', 'invoicing'),
1523
+        'SG' => __('Segovia', 'invoicing'),
1524
+        'SE' => __('Sevilla', 'invoicing'),
1525
+        'SO' => __('Soria', 'invoicing'),
1526
+        'T'  => __('Tarragona', 'invoicing'),
1527
+        'TE' => __('Teruel', 'invoicing'),
1528
+        'TO' => __('Toledo', 'invoicing'),
1529
+        'V'  => __('Valencia', 'invoicing'),
1530
+        'VA' => __('Valladolid', 'invoicing'),
1531
+        'BI' => __('Bizkaia', 'invoicing'),
1532
+        'ZA' => __('Zamora', 'invoicing'),
1533
+        'Z'  => __('Zaragoza', 'invoicing')
1534 1534
     );
1535 1535
 
1536
-    return apply_filters( 'wpinv_spain_states', $states );
1536
+    return apply_filters('wpinv_spain_states', $states);
1537 1537
 }
1538 1538
 
1539 1539
 function wpinv_get_states_field() {
1540
-	if( empty( $_POST['country'] ) ) {
1540
+	if (empty($_POST['country'])) {
1541 1541
 		$_POST['country'] = wpinv_get_default_country();
1542 1542
 	}
1543
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
1543
+	$states = wpinv_get_country_states(sanitize_text_field($_POST['country']));
1544 1544
 
1545
-	if( !empty( $states ) ) {
1546
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
1545
+	if (!empty($states)) {
1546
+		$sanitized_field_name = sanitize_text_field($_POST['field_name']);
1547 1547
         
1548 1548
         $args = array(
1549 1549
 			'name'    => $sanitized_field_name,
1550 1550
 			'id'      => $sanitized_field_name,
1551 1551
 			'class'   => $sanitized_field_name . ' wpinv-select',
1552
-			'options' => array_merge( array( '' => '' ), $states ),
1552
+			'options' => array_merge(array('' => ''), $states),
1553 1553
 			'show_option_all'  => false,
1554 1554
 			'show_option_none' => false
1555 1555
 		);
1556 1556
 
1557
-		$response = wpinv_html_select( $args );
1557
+		$response = wpinv_html_select($args);
1558 1558
 
1559 1559
 	} else {
1560 1560
 		$response = 'nostates';
@@ -1563,8 +1563,8 @@  discard block
 block discarded – undo
1563 1563
 	return $response;
1564 1564
 }
1565 1565
 
1566
-function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
1567
-    $country = !empty( $country ) ? $country : wpinv_get_default_country();
1566
+function wpinv_default_billing_country($country = '', $user_id = 0) {
1567
+    $country = !empty($country) ? $country : wpinv_get_default_country();
1568 1568
     
1569
-    return apply_filters( 'wpinv_default_billing_country', $country, $user_id );
1569
+    return apply_filters('wpinv_default_billing_country', $country, $user_id);
1570 1570
 }
1571 1571
\ No newline at end of file
Please login to merge, or discard this patch.
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.
includes/wpinv-invoice-functions.php 4 patches
Braces   +21 added lines, -16 removed lines patch added patch discarded remove patch
@@ -83,8 +83,9 @@  discard block
 block discarded – undo
83 83
 
84 84
     $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
85 85
 
86
-    if ( $invoice_id != NULL )
87
-        return $invoice_id;
86
+    if ( $invoice_id != NULL ) {
87
+            return $invoice_id;
88
+    }
88 89
 
89 90
     return 0;
90 91
 }
@@ -750,8 +751,9 @@  discard block
 block discarded – undo
750 751
 function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
751 752
     $ret = false;
752 753
 
753
-    if ( empty( $zip ) || empty( $country_code ) )
754
-        return $ret;
754
+    if ( empty( $zip ) || empty( $country_code ) ) {
755
+            return $ret;
756
+    }
755 757
 
756 758
     $country_code = strtoupper( $country_code );
757 759
 
@@ -913,8 +915,9 @@  discard block
 block discarded – undo
913 915
         "ZM" => "\d{5}"
914 916
     );
915 917
 
916
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
917
-        $ret = true;
918
+    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) {
919
+            $ret = true;
920
+    }
918 921
 
919 922
     return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
920 923
 }
@@ -1238,14 +1241,15 @@  discard block
 block discarded – undo
1238 1241
         }
1239 1242
     }
1240 1243
     
1241
-    if ( get_query_var( 'paged' ) )
1242
-        $args['page'] = get_query_var('paged');
1243
-    else if ( get_query_var( 'page' ) )
1244
-        $args['page'] = get_query_var( 'page' );
1245
-    else if ( !empty( $args[ 'page' ] ) )
1246
-        $args['page'] = $args[ 'page' ];
1247
-    else
1248
-        $args['page'] = 1;
1244
+    if ( get_query_var( 'paged' ) ) {
1245
+            $args['page'] = get_query_var('paged');
1246
+    } else if ( get_query_var( 'page' ) ) {
1247
+            $args['page'] = get_query_var( 'page' );
1248
+    } else if ( !empty( $args[ 'page' ] ) ) {
1249
+            $args['page'] = $args[ 'page' ];
1250
+    } else {
1251
+            $args['page'] = 1;
1252
+    }
1249 1253
 
1250 1254
     /**
1251 1255
      * Generate WP_Query args. This logic will change if orders are moved to
@@ -1380,8 +1384,9 @@  discard block
 block discarded – undo
1380 1384
 
1381 1385
 	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1382 1386
 
1383
-	if ( $invoice_id != NULL )
1384
-		return $invoice_id;
1387
+	if ( $invoice_id != NULL ) {
1388
+			return $invoice_id;
1389
+	}
1385 1390
 
1386 1391
 	return 0;
1387 1392
 }
Please login to merge, or discard this patch.
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
 }
665 665
 
666 666
 function wpinv_get_payment_key( $invoice_id = 0 ) {
667
-	$invoice = new WPInv_Invoice( $invoice_id );
667
+    $invoice = new WPInv_Invoice( $invoice_id );
668 668
     return $invoice->get_key();
669 669
 }
670 670
 
@@ -1197,20 +1197,20 @@  discard block
 block discarded – undo
1197 1197
 }
1198 1198
 
1199 1199
 function wpinv_checkout_get_cc_info() {
1200
-	$cc_info = array();
1201
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1202
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1203
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1204
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1205
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1206
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1207
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1208
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1209
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1210
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1211
-
1212
-	// Return cc info
1213
-	return $cc_info;
1200
+    $cc_info = array();
1201
+    $cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1202
+    $cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1203
+    $cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1204
+    $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1205
+    $cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1206
+    $cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1207
+    $cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1208
+    $cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1209
+    $cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1210
+    $cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1211
+
1212
+    // Return cc info
1213
+    return $cc_info;
1214 1214
 }
1215 1215
 
1216 1216
 function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
@@ -1407,7 +1407,7 @@  discard block
 block discarded – undo
1407 1407
         $required_fields  = wpinv_checkout_required_fields();
1408 1408
 
1409 1409
         // Loop through required fields and show error messages
1410
-         if ( !empty( $required_fields ) ) {
1410
+            if ( !empty( $required_fields ) ) {
1411 1411
             foreach ( $required_fields as $field_name => $value ) {
1412 1412
                 if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1413 1413
                     wpinv_set_error( $value['error_id'], $value['error_message'] );
@@ -1513,7 +1513,7 @@  discard block
 block discarded – undo
1513 1513
 }
1514 1514
 
1515 1515
 function wpinv_get_checkout_session() {
1516
-	global $wpi_session;
1516
+    global $wpi_session;
1517 1517
     
1518 1518
     return $wpi_session->get( 'wpinv_checkout' );
1519 1519
 }
@@ -1865,57 +1865,57 @@  discard block
 block discarded – undo
1865 1865
 }
1866 1866
 
1867 1867
 function wpinv_get_invoice_id_by_key( $key ) {
1868
-	global $wpdb;
1868
+    global $wpdb;
1869 1869
 
1870
-	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1870
+    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1871 1871
 
1872
-	if ( $invoice_id != NULL )
1873
-		return $invoice_id;
1872
+    if ( $invoice_id != NULL )
1873
+        return $invoice_id;
1874 1874
 
1875
-	return 0;
1875
+    return 0;
1876 1876
 }
1877 1877
 
1878 1878
 function wpinv_can_view_receipt( $invoice_key = '' ) {
1879
-	$return = false;
1880
-
1881
-	if ( empty( $invoice_key ) ) {
1882
-		return $return;
1883
-	}
1884
-
1885
-	global $wpinv_receipt_args;
1886
-
1887
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1888
-	if ( isset( $_GET['invoice-id'] ) ) {
1889
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1890
-	}
1891
-
1892
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
1893
-		return $return;
1894
-	}
1895
-
1896
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1897
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1898
-		return $return;
1899
-	}
1900
-
1901
-	if ( is_user_logged_in() ) {
1902
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1903
-			$return = true;
1904
-		}
1905
-	}
1906
-
1907
-	$session = wpinv_get_checkout_session();
1908
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1909
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1910
-
1911
-		if ( wpinv_require_login_to_checkout() ) {
1912
-			$return = $return && $check_key === $invoice_key;
1913
-		} else {
1914
-			$return = $check_key === $invoice_key;
1915
-		}
1916
-	}
1917
-
1918
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1879
+    $return = false;
1880
+
1881
+    if ( empty( $invoice_key ) ) {
1882
+        return $return;
1883
+    }
1884
+
1885
+    global $wpinv_receipt_args;
1886
+
1887
+    $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1888
+    if ( isset( $_GET['invoice-id'] ) ) {
1889
+        $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1890
+    }
1891
+
1892
+    if ( empty( $wpinv_receipt_args['id'] ) ) {
1893
+        return $return;
1894
+    }
1895
+
1896
+    $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1897
+    if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1898
+        return $return;
1899
+    }
1900
+
1901
+    if ( is_user_logged_in() ) {
1902
+        if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1903
+            $return = true;
1904
+        }
1905
+    }
1906
+
1907
+    $session = wpinv_get_checkout_session();
1908
+    if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1909
+        $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1910
+
1911
+        if ( wpinv_require_login_to_checkout() ) {
1912
+            $return = $return && $check_key === $invoice_key;
1913
+        } else {
1914
+            $return = $check_key === $invoice_key;
1915
+        }
1916
+    }
1917
+
1918
+    return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1919 1919
 }
1920 1920
 
1921 1921
 function wpinv_pay_for_invoice() {
Please login to merge, or discard this patch.
Doc Comments   +12 added lines patch added patch discarded remove patch
@@ -488,6 +488,9 @@  discard block
 block discarded – undo
488 488
     return $invoice->get_description();
489 489
 }
490 490
 
491
+/**
492
+ * @return string
493
+ */
491 494
 function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
492 495
     $invoice = new WPInv_Invoice( $invoice_id );
493 496
     return $invoice->get_currency();
@@ -521,6 +524,9 @@  discard block
 block discarded – undo
521 524
     return $invoice->get_gateway_title();
522 525
 }
523 526
 
527
+/**
528
+ * @return string
529
+ */
524 530
 function wpinv_get_payment_transaction_id( $invoice_id ) {
525 531
     $invoice = new WPInv_Invoice( $invoice_id );
526 532
     
@@ -616,6 +622,9 @@  discard block
 block discarded – undo
616 622
     return $invoice->get_total( $currency );
617 623
 }
618 624
 
625
+/**
626
+ * @return string
627
+ */
619 628
 function wpinv_get_date_created( $invoice_id = 0, $format = '' ) {
620 629
     $invoice = new WPInv_Invoice( $invoice_id );
621 630
 
@@ -626,6 +635,9 @@  discard block
 block discarded – undo
626 635
     return $date_created;
627 636
 }
628 637
 
638
+/**
639
+ * @return string
640
+ */
629 641
 function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) {
630 642
     $invoice = new WPInv_Invoice( $invoice_id );
631 643
     
Please login to merge, or discard this patch.
Spacing   +736 added lines, -736 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@  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
 function wpinv_get_invoice_cart_id() {
15 15
     $wpinv_checkout = wpinv_get_checkout_session();
16 16
     
17
-    if ( !empty( $wpinv_checkout['invoice_id'] ) ) {
17
+    if (!empty($wpinv_checkout['invoice_id'])) {
18 18
         return $wpinv_checkout['invoice_id'];
19 19
     }
20 20
     
21 21
     return NULL;
22 22
 }
23 23
 
24
-function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) {
25
-    if ( empty( $invoice_data ) ) {
24
+function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) {
25
+    if (empty($invoice_data)) {
26 26
         return false;
27 27
     }
28 28
     
29
-    if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) {
30
-        return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast on item.', 'invoicing' ) ) : 0;
29
+    if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) {
30
+        return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast on item.', 'invoicing')) : 0;
31 31
     }
32 32
     
33
-    if ( empty( $invoice_data['user_id'] ) ) {
33
+    if (empty($invoice_data['user_id'])) {
34 34
         $invoice_data['user_id'] = get_current_user_id();
35 35
     }
36 36
     
37
-    $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0;
37
+    $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0;
38 38
     
39
-    if ( empty( $invoice_data['status'] ) ) {
39
+    if (empty($invoice_data['status'])) {
40 40
         $invoice_data['status'] = 'wpi-pending';
41 41
     }
42 42
     
43
-    if ( empty( $invoice_data['ip'] ) ) {
43
+    if (empty($invoice_data['ip'])) {
44 44
         $invoice_data['ip'] = wpinv_get_ip();
45 45
     }
46 46
 
@@ -51,12 +51,12 @@  discard block
 block discarded – undo
51 51
         'status'        => $invoice_data['status'],
52 52
     );
53 53
 
54
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data, true );
55
-    if ( is_wp_error( $invoice ) ) {
54
+    $invoice = wpinv_create_invoice($default_args, $invoice_data, true);
55
+    if (is_wp_error($invoice)) {
56 56
         return $wp_error ? $invoice : 0;
57 57
     }
58 58
     
59
-    if ( empty( $invoice_data['invoice_id'] ) ) {
59
+    if (empty($invoice_data['invoice_id'])) {
60 60
         //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
61 61
     }
62 62
     
@@ -79,24 +79,24 @@  discard block
 block discarded – undo
79 79
         'discount'              => array(),
80 80
     );
81 81
 
82
-    if ( $user_id = (int)$invoice->get_user_id() ) {
83
-        if ( $user_address = wpinv_get_user_address( $user_id ) ) {
84
-            $default_user_info = wp_parse_args( $user_address, $default_user_info );
82
+    if ($user_id = (int)$invoice->get_user_id()) {
83
+        if ($user_address = wpinv_get_user_address($user_id)) {
84
+            $default_user_info = wp_parse_args($user_address, $default_user_info);
85 85
         }
86 86
     }
87 87
     
88
-    if ( empty( $invoice_data['user_info'] ) ) {
88
+    if (empty($invoice_data['user_info'])) {
89 89
         $invoice_data['user_info'] = array();
90 90
     }
91 91
     
92
-    $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info );
92
+    $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info);
93 93
     
94
-    if ( empty( $user_info['first_name'] ) ) {
94
+    if (empty($user_info['first_name'])) {
95 95
         $user_info['first_name'] = $default_user_info['first_name'];
96 96
         $user_info['last_name'] = $default_user_info['last_name'];
97 97
     }
98 98
     
99
-    if ( empty( $user_info['country'] ) ) {
99
+    if (empty($user_info['country'])) {
100 100
         $user_info['country'] = $default_user_info['country'];
101 101
         $user_info['state'] = $default_user_info['state'];
102 102
         $user_info['city'] = $default_user_info['city'];
@@ -105,13 +105,13 @@  discard block
 block discarded – undo
105 105
         $user_info['phone'] = $default_user_info['phone'];
106 106
     }
107 107
     
108
-    if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) {
108
+    if (!empty($user_info['discount']) && !is_array($user_info['discount'])) {
109 109
         $user_info['discount'] = (array)$user_info['discount'];
110 110
     }
111 111
 
112 112
     // Payment details
113 113
     $payment_details = array();
114
-    if ( !empty( $invoice_data['payment_details'] ) ) {
114
+    if (!empty($invoice_data['payment_details'])) {
115 115
         $default_payment_details = array(
116 116
             'gateway'           => 'manual',
117 117
             'gateway_title'     => '',
@@ -119,56 +119,56 @@  discard block
 block discarded – undo
119 119
             'transaction_id'    => '',
120 120
         );
121 121
         
122
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details );
122
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details);
123 123
         
124
-        if ( empty( $payment_details['gateway'] ) ) {
124
+        if (empty($payment_details['gateway'])) {
125 125
             $payment_details['gateway'] = 'manual';
126 126
         }
127 127
         
128
-        if ( empty( $payment_details['currency'] ) ) {
128
+        if (empty($payment_details['currency'])) {
129 129
             $payment_details['currency'] = wpinv_get_default_country();
130 130
         }
131 131
         
132
-        if ( empty( $payment_details['gateway_title'] ) ) {
133
-            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] );
132
+        if (empty($payment_details['gateway_title'])) {
133
+            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']);
134 134
         }
135 135
     }
136 136
     
137
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) );
138
-    
139
-    if ( !empty( $payment_details ) ) {
140
-        $invoice->set( 'currency', $payment_details['currency'] );
141
-        $invoice->set( 'gateway', $payment_details['gateway'] );
142
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
143
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
144
-    }
145
-    
146
-    $invoice->set( 'user_info', $user_info );
147
-    $invoice->set( 'first_name', $user_info['first_name'] );
148
-    $invoice->set( 'last_name', $user_info['last_name'] );
149
-    $invoice->set( 'address', $user_info['address'] );
150
-    $invoice->set( 'company', $user_info['company'] );
151
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
152
-    $invoice->set( 'phone', $user_info['phone'] );
153
-    $invoice->set( 'city', $user_info['city'] );
154
-    $invoice->set( 'country', $user_info['country'] );
155
-    $invoice->set( 'state', $user_info['state'] );
156
-    $invoice->set( 'zip', $user_info['zip'] );
157
-    $invoice->set( 'discounts', $user_info['discount'] );
158
-    $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) );
159
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
160
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
161
-    
162
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
163
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
164
-            $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
165
-            $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
166
-            $name           = !empty( $item['name'] ) ? $item['name'] : '';
167
-            $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : '';
137
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending'));
138
+    
139
+    if (!empty($payment_details)) {
140
+        $invoice->set('currency', $payment_details['currency']);
141
+        $invoice->set('gateway', $payment_details['gateway']);
142
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
143
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
144
+    }
145
+    
146
+    $invoice->set('user_info', $user_info);
147
+    $invoice->set('first_name', $user_info['first_name']);
148
+    $invoice->set('last_name', $user_info['last_name']);
149
+    $invoice->set('address', $user_info['address']);
150
+    $invoice->set('company', $user_info['company']);
151
+    $invoice->set('vat_number', $user_info['vat_number']);
152
+    $invoice->set('phone', $user_info['phone']);
153
+    $invoice->set('city', $user_info['city']);
154
+    $invoice->set('country', $user_info['country']);
155
+    $invoice->set('state', $user_info['state']);
156
+    $invoice->set('zip', $user_info['zip']);
157
+    $invoice->set('discounts', $user_info['discount']);
158
+    $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip()));
159
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
160
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
161
+    
162
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
163
+        foreach ($invoice_data['cart_details'] as $key => $item) {
164
+            $item_id        = !empty($item['id']) ? $item['id'] : 0;
165
+            $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
166
+            $name           = !empty($item['name']) ? $item['name'] : '';
167
+            $item_price     = isset($item['item_price']) ? $item['item_price'] : '';
168 168
             
169
-            $post_item  = new WPInv_Item( $item_id );
170
-            if ( !empty( $post_item ) ) {
171
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
169
+            $post_item = new WPInv_Item($item_id);
170
+            if (!empty($post_item)) {
171
+                $name       = !empty($name) ? $name : $post_item->get_name();
172 172
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
173 173
             } else {
174 174
                 continue;
@@ -178,253 +178,253 @@  discard block
 block discarded – undo
178 178
                 'name'          => $name,
179 179
                 'quantity'      => $quantity,
180 180
                 'item_price'    => $item_price,
181
-                'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
182
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
183
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
184
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
185
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
181
+                'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
182
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
183
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
184
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
185
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
186 186
             );
187 187
 
188
-            $invoice->add_item( $item_id, $args );
188
+            $invoice->add_item($item_id, $args);
189 189
         }
190 190
     }
191 191
 
192
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
192
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
193 193
 
194
-    if ( isset( $invoice_data['post_date'] ) ) {
195
-        $invoice->set( 'date', $invoice_data['post_date'] );
194
+    if (isset($invoice_data['post_date'])) {
195
+        $invoice->set('date', $invoice_data['post_date']);
196 196
     }
197 197
     
198 198
     // Invoice due date
199
-    if ( isset( $invoice_data['due_date'] ) ) {
200
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
199
+    if (isset($invoice_data['due_date'])) {
200
+        $invoice->set('due_date', $invoice_data['due_date']);
201 201
     }
202 202
     
203 203
     $invoice->save();
204 204
     
205 205
     // Add notes
206
-    if ( !empty( $invoice_data['private_note'] ) ) {
207
-        $invoice->add_note( $invoice_data['private_note'] );
206
+    if (!empty($invoice_data['private_note'])) {
207
+        $invoice->add_note($invoice_data['private_note']);
208 208
     }
209
-    if ( !empty( $invoice_data['user_note'] ) ) {
210
-        $invoice->add_note( $invoice_data['user_note'], true );
209
+    if (!empty($invoice_data['user_note'])) {
210
+        $invoice->add_note($invoice_data['user_note'], true);
211 211
     }
212 212
     
213
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
213
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
214 214
 
215
-    if ( ! empty( $invoice->ID ) ) {
215
+    if (!empty($invoice->ID)) {
216 216
         global $wpi_userID, $wpinv_ip_address_country;
217 217
         
218 218
         $checkout_session = wpinv_get_checkout_session();
219 219
         
220 220
         $data_session                   = array();
221 221
         $data_session['invoice_id']     = $invoice->ID;
222
-        $data_session['cart_discounts'] = $invoice->get_discounts( true );
222
+        $data_session['cart_discounts'] = $invoice->get_discounts(true);
223 223
         
224
-        wpinv_set_checkout_session( $data_session );
224
+        wpinv_set_checkout_session($data_session);
225 225
         
226 226
         $wpi_userID         = (int)$invoice->get_user_id();
227 227
         
228
-        $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
228
+        $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
229 229
         $_POST['state']     = $invoice->state;
230 230
 
231
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
232
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
231
+        $invoice->set('country', sanitize_text_field($_POST['country']));
232
+        $invoice->set('state', sanitize_text_field($_POST['state']));
233 233
         
234 234
         $wpinv_ip_address_country = $invoice->country;
235 235
         
236
-        $invoice = $invoice->recalculate_totals( true );
236
+        $invoice = $invoice->recalculate_totals(true);
237 237
         
238
-        wpinv_set_checkout_session( $checkout_session );
238
+        wpinv_set_checkout_session($checkout_session);
239 239
                     
240 240
         return $invoice;
241 241
     }
242 242
     
243
-    if ( $wp_error ) {
244
-        if ( is_wp_error( $invoice ) ) {
243
+    if ($wp_error) {
244
+        if (is_wp_error($invoice)) {
245 245
             return $invoice;
246 246
         } else {
247
-            return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) );
247
+            return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing'));
248 248
         }
249 249
     } else {
250 250
         return 0;
251 251
     }
252 252
 }
253 253
 
254
-function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) {
255
-    $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL;
254
+function wpinv_update_invoice($invoice_data = array(), $wp_error = false) {
255
+    $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL;
256 256
 
257
-    if ( !$invoice_ID ) {
258
-        if ( $wp_error ) {
259
-            return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) );
257
+    if (!$invoice_ID) {
258
+        if ($wp_error) {
259
+            return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing'));
260 260
         }
261 261
         return 0;
262 262
     }
263 263
 
264
-    $invoice = wpinv_get_invoice( $invoice_ID );
264
+    $invoice = wpinv_get_invoice($invoice_ID);
265 265
 
266
-    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL;
266
+    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL;
267 267
 
268
-    if ( empty( $invoice->ID ) ) {
269
-        if ( $wp_error ) {
270
-            return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) );
268
+    if (empty($invoice->ID)) {
269
+        if ($wp_error) {
270
+            return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing'));
271 271
         }
272 272
         return 0;
273 273
     }
274 274
 
275
-    if ( !$invoice->has_status( array( 'wpi-pending' ) ) ) {
276
-        if ( $wp_error ) {
277
-            return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) );
275
+    if (!$invoice->has_status(array('wpi-pending'))) {
276
+        if ($wp_error) {
277
+            return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing'));
278 278
         }
279 279
         return 0;
280 280
     }
281 281
 
282 282
     // Invoice status
283
-    if ( !empty( $invoice_data['status'] ) ) {
284
-        $invoice->set( 'status', $invoice_data['status'] );
283
+    if (!empty($invoice_data['status'])) {
284
+        $invoice->set('status', $invoice_data['status']);
285 285
     }
286 286
 
287 287
     // Invoice date
288
-    if ( !empty( $invoice_data['post_date'] ) ) {
289
-        $invoice->set( 'date', $invoice_data['post_date'] );
288
+    if (!empty($invoice_data['post_date'])) {
289
+        $invoice->set('date', $invoice_data['post_date']);
290 290
     }
291 291
 
292 292
     // Invoice due date
293
-    if ( isset( $invoice_data['due_date'] ) ) {
294
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
293
+    if (isset($invoice_data['due_date'])) {
294
+        $invoice->set('due_date', $invoice_data['due_date']);
295 295
     }
296 296
 
297 297
     // Invoice IP address
298
-    if ( !empty( $invoice_data['ip'] ) ) {
299
-        $invoice->set( 'ip', $invoice_data['ip'] );
298
+    if (!empty($invoice_data['ip'])) {
299
+        $invoice->set('ip', $invoice_data['ip']);
300 300
     }
301 301
     
302 302
     // User info
303
-    if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) {
304
-        $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info );
303
+    if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) {
304
+        $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info);
305 305
 
306
-        if ( $discounts = $invoice->get_discounts() ) {
306
+        if ($discounts = $invoice->get_discounts()) {
307 307
             $set_discount = $discounts;
308 308
         } else {
309 309
             $set_discount = '';
310 310
         }
311 311
 
312 312
         // Manage discount
313
-        if ( !empty( $invoice_data['user_info']['discount'] ) ) {
313
+        if (!empty($invoice_data['user_info']['discount'])) {
314 314
             // Remove discount
315
-            if ( $invoice_data['user_info']['discount'] == 'none' ) {
315
+            if ($invoice_data['user_info']['discount'] == 'none') {
316 316
                 $set_discount = '';
317 317
             } else {
318 318
                 $set_discount = $invoice_data['user_info']['discount'];
319 319
             }
320 320
 
321
-            $invoice->set( 'discounts', $set_discount );
321
+            $invoice->set('discounts', $set_discount);
322 322
         }
323 323
 
324 324
         $user_info['discount'] = $set_discount;
325 325
 
326
-        $invoice->set( 'user_info', $user_info );
326
+        $invoice->set('user_info', $user_info);
327 327
     }
328 328
 
329
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) {
330
-        $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array();
329
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) {
330
+        $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array();
331 331
 
332
-        if ( !empty( $remove_items[0]['id'] ) ) {
333
-            foreach ( $remove_items as $item ) {
334
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
335
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
336
-                if ( empty( $item_id ) ) {
332
+        if (!empty($remove_items[0]['id'])) {
333
+            foreach ($remove_items as $item) {
334
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
335
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
336
+                if (empty($item_id)) {
337 337
                     continue;
338 338
                 }
339 339
 
340
-                foreach ( $invoice->cart_details as $cart_index => $cart_item ) {
341
-                    if ( $item_id == $cart_item['id'] ) {
340
+                foreach ($invoice->cart_details as $cart_index => $cart_item) {
341
+                    if ($item_id == $cart_item['id']) {
342 342
                         $args = array(
343 343
                             'id'         => $item_id,
344 344
                             'quantity'   => $quantity,
345 345
                             'cart_index' => $cart_index
346 346
                         );
347 347
 
348
-                        $invoice->remove_item( $item_id, $args );
348
+                        $invoice->remove_item($item_id, $args);
349 349
                         break;
350 350
                     }
351 351
                 }
352 352
             }
353 353
         }
354 354
 
355
-        $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array();
355
+        $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array();
356 356
 
357
-        if ( !empty( $add_items[0]['id'] ) ) {
358
-            foreach ( $add_items as $item ) {
359
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
360
-                $post_item      = new WPInv_Item( $item_id );
361
-                if ( empty( $post_item ) ) {
357
+        if (!empty($add_items[0]['id'])) {
358
+            foreach ($add_items as $item) {
359
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
360
+                $post_item      = new WPInv_Item($item_id);
361
+                if (empty($post_item)) {
362 362
                     continue;
363 363
                 }
364 364
 
365 365
                 $valid_item = true;
366
-                if ( !empty( $recurring_item ) ) {
367
-                    if ( $recurring_item->ID != $item_id ) {
366
+                if (!empty($recurring_item)) {
367
+                    if ($recurring_item->ID != $item_id) {
368 368
                         $valid_item = false;
369 369
                     }
370
-                } else if ( wpinv_is_recurring_item( $item_id ) ) {
370
+                } else if (wpinv_is_recurring_item($item_id)) {
371 371
                     $valid_item = false;
372 372
                 }
373 373
                 
374
-                if ( !$valid_item ) {
375
-                    if ( $wp_error ) {
376
-                        return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) );
374
+                if (!$valid_item) {
375
+                    if ($wp_error) {
376
+                        return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing'));
377 377
                     }
378 378
                     return 0;
379 379
                 }
380 380
 
381
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
382
-                $name           = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name();
383
-                $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price();
381
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
382
+                $name           = !empty($item['name']) ? $item['name'] : $post_item->get_name();
383
+                $item_price     = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price();
384 384
 
385 385
                 $args = array(
386 386
                     'name'          => $name,
387 387
                     'quantity'      => $quantity,
388 388
                     'item_price'    => $item_price,
389
-                    'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
390
-                    'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0,
391
-                    'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
392
-                    'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
393
-                    'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
389
+                    'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
390
+                    'tax'           => !empty($item['tax']) ? $item['tax'] : 0,
391
+                    'discount'      => isset($item['discount']) ? $item['discount'] : 0,
392
+                    'meta'          => isset($item['meta']) ? $item['meta'] : array(),
393
+                    'fees'          => isset($item['fees']) ? $item['fees'] : array(),
394 394
                 );
395 395
 
396
-                $invoice->add_item( $item_id, $args );
396
+                $invoice->add_item($item_id, $args);
397 397
             }
398 398
         }
399 399
     }
400 400
     
401 401
     // Payment details
402
-    if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) {
403
-        if ( !empty( $payment_details['gateway'] ) ) {
404
-            $invoice->set( 'gateway', $payment_details['gateway'] );
402
+    if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) {
403
+        if (!empty($payment_details['gateway'])) {
404
+            $invoice->set('gateway', $payment_details['gateway']);
405 405
         }
406 406
 
407
-        if ( !empty( $payment_details['transaction_id'] ) ) {
408
-            $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
407
+        if (!empty($payment_details['transaction_id'])) {
408
+            $invoice->set('transaction_id', $payment_details['transaction_id']);
409 409
         }
410 410
     }
411 411
 
412
-    do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data );
412
+    do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data);
413 413
 
414 414
     // Parent invoice
415
-    if ( !empty( $invoice_data['parent'] ) ) {
416
-        $invoice->set( 'parent_invoice', $invoice_data['parent'] );
415
+    if (!empty($invoice_data['parent'])) {
416
+        $invoice->set('parent_invoice', $invoice_data['parent']);
417 417
     }
418 418
 
419 419
     // Save invoice data.
420 420
     $invoice->save();
421 421
     
422
-    if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) {
423
-        if ( $wp_error ) {
424
-            if ( is_wp_error( $invoice ) ) {
422
+    if (empty($invoice->ID) || is_wp_error($invoice)) {
423
+        if ($wp_error) {
424
+            if (is_wp_error($invoice)) {
425 425
                 return $invoice;
426 426
             } else {
427
-                return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) );
427
+                return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing'));
428 428
             }
429 429
         } else {
430 430
             return 0;
@@ -432,13 +432,13 @@  discard block
 block discarded – undo
432 432
     }
433 433
 
434 434
     // Add private note
435
-    if ( !empty( $invoice_data['private_note'] ) ) {
436
-        $invoice->add_note( $invoice_data['private_note'] );
435
+    if (!empty($invoice_data['private_note'])) {
436
+        $invoice->add_note($invoice_data['private_note']);
437 437
     }
438 438
 
439 439
     // Add user note
440
-    if ( !empty( $invoice_data['user_note'] ) ) {
441
-        $invoice->add_note( $invoice_data['user_note'], true );
440
+    if (!empty($invoice_data['user_note'])) {
441
+        $invoice->add_note($invoice_data['user_note'], true);
442 442
     }
443 443
 
444 444
     global $wpi_userID, $wpinv_ip_address_country;
@@ -447,445 +447,445 @@  discard block
 block discarded – undo
447 447
 
448 448
     $data_session                   = array();
449 449
     $data_session['invoice_id']     = $invoice->ID;
450
-    $data_session['cart_discounts'] = $invoice->get_discounts( true );
450
+    $data_session['cart_discounts'] = $invoice->get_discounts(true);
451 451
 
452
-    wpinv_set_checkout_session( $data_session );
452
+    wpinv_set_checkout_session($data_session);
453 453
 
454 454
     $wpi_userID         = (int)$invoice->get_user_id();
455 455
 
456
-    $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
456
+    $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
457 457
     $_POST['state']     = $invoice->state;
458 458
 
459
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
460
-    $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
459
+    $invoice->set('country', sanitize_text_field($_POST['country']));
460
+    $invoice->set('state', sanitize_text_field($_POST['state']));
461 461
 
462 462
     $wpinv_ip_address_country = $invoice->country;
463 463
 
464
-    $invoice = $invoice->recalculate_totals( true );
464
+    $invoice = $invoice->recalculate_totals(true);
465 465
 
466
-    do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data );
466
+    do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data);
467 467
 
468
-    wpinv_set_checkout_session( $checkout_session );
468
+    wpinv_set_checkout_session($checkout_session);
469 469
 
470 470
     return $invoice;
471 471
 }
472 472
 
473
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
474
-    if ( $cart && empty( $invoice_id ) ) {
473
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
474
+    if ($cart && empty($invoice_id)) {
475 475
         $invoice_id = (int)wpinv_get_invoice_cart_id();
476 476
     }
477 477
 
478
-    $invoice = new WPInv_Invoice( $invoice_id );
478
+    $invoice = new WPInv_Invoice($invoice_id);
479 479
     return $invoice;
480 480
 }
481 481
 
482
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
483
-    return wpinv_get_invoice( $invoice_id, true );
482
+function wpinv_get_invoice_cart($invoice_id = 0) {
483
+    return wpinv_get_invoice($invoice_id, true);
484 484
 }
485 485
 
486
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
487
-    $invoice = new WPInv_Invoice( $invoice_id );
486
+function wpinv_get_invoice_description($invoice_id = 0) {
487
+    $invoice = new WPInv_Invoice($invoice_id);
488 488
     return $invoice->get_description();
489 489
 }
490 490
 
491
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
492
-    $invoice = new WPInv_Invoice( $invoice_id );
491
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
492
+    $invoice = new WPInv_Invoice($invoice_id);
493 493
     return $invoice->get_currency();
494 494
 }
495 495
 
496
-function wpinv_get_payment_user_email( $invoice_id ) {
497
-    $invoice = new WPInv_Invoice( $invoice_id );
496
+function wpinv_get_payment_user_email($invoice_id) {
497
+    $invoice = new WPInv_Invoice($invoice_id);
498 498
     return $invoice->get_email();
499 499
 }
500 500
 
501
-function wpinv_get_user_id( $invoice_id ) {
502
-    $invoice = new WPInv_Invoice( $invoice_id );
501
+function wpinv_get_user_id($invoice_id) {
502
+    $invoice = new WPInv_Invoice($invoice_id);
503 503
     return $invoice->get_user_id();
504 504
 }
505 505
 
506
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
507
-    $invoice = new WPInv_Invoice( $invoice_id );
506
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
507
+    $invoice = new WPInv_Invoice($invoice_id);
508 508
     
509
-    return $invoice->get_status( $return_label );
509
+    return $invoice->get_status($return_label);
510 510
 }
511 511
 
512
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
513
-    $invoice = new WPInv_Invoice( $invoice_id );
512
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
513
+    $invoice = new WPInv_Invoice($invoice_id);
514 514
     
515
-    return $invoice->get_gateway( $return_label );
515
+    return $invoice->get_gateway($return_label);
516 516
 }
517 517
 
518
-function wpinv_get_payment_gateway_name( $invoice_id ) {
519
-    $invoice = new WPInv_Invoice( $invoice_id );
518
+function wpinv_get_payment_gateway_name($invoice_id) {
519
+    $invoice = new WPInv_Invoice($invoice_id);
520 520
     
521 521
     return $invoice->get_gateway_title();
522 522
 }
523 523
 
524
-function wpinv_get_payment_transaction_id( $invoice_id ) {
525
-    $invoice = new WPInv_Invoice( $invoice_id );
524
+function wpinv_get_payment_transaction_id($invoice_id) {
525
+    $invoice = new WPInv_Invoice($invoice_id);
526 526
     
527 527
     return $invoice->get_transaction_id();
528 528
 }
529 529
 
530
-function wpinv_get_id_by_transaction_id( $key ) {
530
+function wpinv_get_id_by_transaction_id($key) {
531 531
     global $wpdb;
532 532
 
533
-    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
533
+    $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key));
534 534
 
535
-    if ( $invoice_id != NULL )
535
+    if ($invoice_id != NULL)
536 536
         return $invoice_id;
537 537
 
538 538
     return 0;
539 539
 }
540 540
 
541
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
542
-    $invoice = new WPInv_Invoice( $invoice_id );
541
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
542
+    $invoice = new WPInv_Invoice($invoice_id);
543 543
 
544
-    return $invoice->get_meta( $meta_key, $single );
544
+    return $invoice->get_meta($meta_key, $single);
545 545
 }
546 546
 
547
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
548
-    $invoice = new WPInv_Invoice( $invoice_id );
547
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
548
+    $invoice = new WPInv_Invoice($invoice_id);
549 549
     
550
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
550
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
551 551
 }
552 552
 
553
-function wpinv_get_items( $invoice_id = 0 ) {
554
-    $invoice            = wpinv_get_invoice( $invoice_id );
553
+function wpinv_get_items($invoice_id = 0) {
554
+    $invoice            = wpinv_get_invoice($invoice_id);
555 555
     
556 556
     $items              = $invoice->get_items();
557 557
     $invoice_currency   = $invoice->get_currency();
558 558
 
559
-    if ( !empty( $items ) && is_array( $items ) ) {
560
-        foreach ( $items as $key => $item ) {
559
+    if (!empty($items) && is_array($items)) {
560
+        foreach ($items as $key => $item) {
561 561
             $items[$key]['currency'] = $invoice_currency;
562 562
 
563
-            if ( !isset( $cart_item['subtotal'] ) ) {
563
+            if (!isset($cart_item['subtotal'])) {
564 564
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
565 565
             }
566 566
         }
567 567
     }
568 568
 
569
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
569
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
570 570
 }
571 571
 
572
-function wpinv_get_fees( $invoice_id = 0 ) {
573
-    $invoice           = wpinv_get_invoice( $invoice_id );
572
+function wpinv_get_fees($invoice_id = 0) {
573
+    $invoice           = wpinv_get_invoice($invoice_id);
574 574
     $fees              = $invoice->get_fees();
575 575
 
576
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
576
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
577 577
 }
578 578
 
579
-function wpinv_get_invoice_ip( $invoice_id ) {
580
-    $invoice = new WPInv_Invoice( $invoice_id );
579
+function wpinv_get_invoice_ip($invoice_id) {
580
+    $invoice = new WPInv_Invoice($invoice_id);
581 581
     return $invoice->get_ip();
582 582
 }
583 583
 
584
-function wpinv_get_invoice_user_info( $invoice_id ) {
585
-    $invoice = new WPInv_Invoice( $invoice_id );
584
+function wpinv_get_invoice_user_info($invoice_id) {
585
+    $invoice = new WPInv_Invoice($invoice_id);
586 586
     return $invoice->get_user_info();
587 587
 }
588 588
 
589
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
590
-    $invoice = new WPInv_Invoice( $invoice_id );
589
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
590
+    $invoice = new WPInv_Invoice($invoice_id);
591 591
 
592
-    return $invoice->get_subtotal( $currency );
592
+    return $invoice->get_subtotal($currency);
593 593
 }
594 594
 
595
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
596
-    $invoice = new WPInv_Invoice( $invoice_id );
595
+function wpinv_tax($invoice_id = 0, $currency = false) {
596
+    $invoice = new WPInv_Invoice($invoice_id);
597 597
 
598
-    return $invoice->get_tax( $currency );
598
+    return $invoice->get_tax($currency);
599 599
 }
600 600
 
601
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
602
-    $invoice = wpinv_get_invoice( $invoice_id );
601
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
602
+    $invoice = wpinv_get_invoice($invoice_id);
603 603
 
604
-    return $invoice->get_discount( $currency, $dash );
604
+    return $invoice->get_discount($currency, $dash);
605 605
 }
606 606
 
607
-function wpinv_discount_code( $invoice_id = 0 ) {
608
-    $invoice = new WPInv_Invoice( $invoice_id );
607
+function wpinv_discount_code($invoice_id = 0) {
608
+    $invoice = new WPInv_Invoice($invoice_id);
609 609
 
610 610
     return $invoice->get_discount_code();
611 611
 }
612 612
 
613
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
614
-    $invoice = new WPInv_Invoice( $invoice_id );
613
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
614
+    $invoice = new WPInv_Invoice($invoice_id);
615 615
 
616
-    return $invoice->get_total( $currency );
616
+    return $invoice->get_total($currency);
617 617
 }
618 618
 
619
-function wpinv_get_date_created( $invoice_id = 0, $format = '' ) {
620
-    $invoice = new WPInv_Invoice( $invoice_id );
619
+function wpinv_get_date_created($invoice_id = 0, $format = '') {
620
+    $invoice = new WPInv_Invoice($invoice_id);
621 621
 
622
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
622
+    $format         = !empty($format) ? $format : get_option('date_format');
623 623
     $date_created   = $invoice->get_created_date();
624
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
624
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
625 625
 
626 626
     return $date_created;
627 627
 }
628 628
 
629
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) {
630
-    $invoice = new WPInv_Invoice( $invoice_id );
629
+function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) {
630
+    $invoice = new WPInv_Invoice($invoice_id);
631 631
     
632
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
632
+    $format         = !empty($format) ? $format : get_option('date_format');
633 633
     $date_completed = $invoice->get_completed_date();
634
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
635
-    if ( $invoice_date == '' && $default ) {
636
-        $invoice_date   = wpinv_get_date_created( $invoice_id, $format );
634
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
635
+    if ($invoice_date == '' && $default) {
636
+        $invoice_date = wpinv_get_date_created($invoice_id, $format);
637 637
     }
638 638
 
639 639
     return $invoice_date;
640 640
 }
641 641
 
642
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
643
-    $invoice = new WPInv_Invoice( $invoice_id );
642
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
643
+    $invoice = new WPInv_Invoice($invoice_id);
644 644
     
645 645
     return $invoice->vat_number;
646 646
 }
647 647
 
648
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) {
649
-    $invoice = new WPInv_Invoice( $invoice_id );
648
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) {
649
+    $invoice = new WPInv_Invoice($invoice_id);
650 650
 
651
-    return $invoice->add_note( $note, $user_type, $added_by_user, $system );
651
+    return $invoice->add_note($note, $user_type, $added_by_user, $system);
652 652
 }
653 653
 
654
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
654
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
655 655
     global $invoicing;
656 656
     
657
-    if ( empty( $invoice_id ) ) {
657
+    if (empty($invoice_id)) {
658 658
         return NULL;
659 659
     }
660 660
     
661
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
661
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
662 662
     
663
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
663
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
664 664
 }
665 665
 
666
-function wpinv_get_payment_key( $invoice_id = 0 ) {
667
-	$invoice = new WPInv_Invoice( $invoice_id );
666
+function wpinv_get_payment_key($invoice_id = 0) {
667
+	$invoice = new WPInv_Invoice($invoice_id);
668 668
     return $invoice->get_key();
669 669
 }
670 670
 
671
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
672
-    $invoice = new WPInv_Invoice( $invoice_id );
671
+function wpinv_get_invoice_number($invoice_id = 0) {
672
+    $invoice = new WPInv_Invoice($invoice_id);
673 673
     return $invoice->get_number();
674 674
 }
675 675
 
676
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
676
+function wpinv_get_cart_discountable_subtotal($code_id) {
677 677
     $cart_items = wpinv_get_cart_content_details();
678 678
     $items      = array();
679 679
 
680
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
680
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
681 681
 
682
-    if( $cart_items ) {
682
+    if ($cart_items) {
683 683
 
684
-        foreach( $cart_items as $item ) {
684
+        foreach ($cart_items as $item) {
685 685
 
686
-            if( ! in_array( $item['id'], $excluded_items ) ) {
687
-                $items[] =  $item;
686
+            if (!in_array($item['id'], $excluded_items)) {
687
+                $items[] = $item;
688 688
             }
689 689
         }
690 690
     }
691 691
 
692
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
692
+    $subtotal = wpinv_get_cart_items_subtotal($items);
693 693
 
694
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
694
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
695 695
 }
696 696
 
697
-function wpinv_get_cart_items_subtotal( $items ) {
697
+function wpinv_get_cart_items_subtotal($items) {
698 698
     $subtotal = 0.00;
699 699
 
700
-    if ( is_array( $items ) && ! empty( $items ) ) {
701
-        $prices = wp_list_pluck( $items, 'subtotal' );
700
+    if (is_array($items) && !empty($items)) {
701
+        $prices = wp_list_pluck($items, 'subtotal');
702 702
 
703
-        if( is_array( $prices ) ) {
704
-            $subtotal = array_sum( $prices );
703
+        if (is_array($prices)) {
704
+            $subtotal = array_sum($prices);
705 705
         } else {
706 706
             $subtotal = 0.00;
707 707
         }
708 708
 
709
-        if( $subtotal < 0 ) {
709
+        if ($subtotal < 0) {
710 710
             $subtotal = 0.00;
711 711
         }
712 712
     }
713 713
 
714
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
714
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
715 715
 }
716 716
 
717
-function wpinv_get_cart_subtotal( $items = array() ) {
718
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
719
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
717
+function wpinv_get_cart_subtotal($items = array()) {
718
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
719
+    $subtotal = wpinv_get_cart_items_subtotal($items);
720 720
 
721
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
721
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
722 722
 }
723 723
 
724
-function wpinv_cart_subtotal( $items = array() ) {
725
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) );
724
+function wpinv_cart_subtotal($items = array()) {
725
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)));
726 726
 
727 727
     return $price;
728 728
 }
729 729
 
730
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
731
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
732
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
733
-    $cart_tax  = (float)wpinv_get_cart_tax( $items );
730
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
731
+    $subtotal  = (float)wpinv_get_cart_subtotal($items);
732
+    $discounts = (float)wpinv_get_cart_discounted_amount($items);
733
+    $cart_tax  = (float)wpinv_get_cart_tax($items);
734 734
     $fees      = (float)wpinv_get_cart_fee_total();
735
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
735
+    if (!empty($invoice) && $invoice->is_free_trial()) {
736 736
         $total = 0;
737 737
     } else {
738
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
738
+        $total = $subtotal - $discounts + $cart_tax + $fees;
739 739
     }
740 740
 
741
-    if ( $total < 0 ) {
741
+    if ($total < 0) {
742 742
         $total = 0.00;
743 743
     }
744 744
     
745
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
745
+    $total = (float)apply_filters('wpinv_get_cart_total', $total, $items);
746 746
 
747
-    return wpinv_sanitize_amount( $total );
747
+    return wpinv_sanitize_amount($total);
748 748
 }
749 749
 
750
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
750
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
751 751
     global $cart_total;
752
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) );
753
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
752
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)));
753
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
754 754
     
755 755
     $cart_total = $total;
756 756
 
757
-    if ( !$echo ) {
757
+    if (!$echo) {
758 758
         return $total;
759 759
     }
760 760
 
761 761
     echo $total;
762 762
 }
763 763
 
764
-function wpinv_get_cart_tax( $items = array() ) {
764
+function wpinv_get_cart_tax($items = array()) {
765 765
     $cart_tax = 0;
766
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
766
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
767 767
 
768
-    if ( $items ) {
769
-        $taxes = wp_list_pluck( $items, 'tax' );
768
+    if ($items) {
769
+        $taxes = wp_list_pluck($items, 'tax');
770 770
 
771
-        if( is_array( $taxes ) ) {
772
-            $cart_tax = array_sum( $taxes );
771
+        if (is_array($taxes)) {
772
+            $cart_tax = array_sum($taxes);
773 773
         }
774 774
     }
775 775
 
776 776
     $cart_tax += wpinv_get_cart_fee_tax();
777 777
 
778
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
778
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
779 779
 }
780 780
 
781
-function wpinv_cart_tax( $items = array(), $echo = false ) {
782
-    $cart_tax = wpinv_get_cart_tax( $items );
783
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) );
781
+function wpinv_cart_tax($items = array(), $echo = false) {
782
+    $cart_tax = wpinv_get_cart_tax($items);
783
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax));
784 784
 
785
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
785
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
786 786
 
787
-    if ( !$echo ) {
787
+    if (!$echo) {
788 788
         return $tax;
789 789
     }
790 790
 
791 791
     echo $tax;
792 792
 }
793 793
 
794
-function wpinv_get_cart_discount_code( $items = array() ) {
794
+function wpinv_get_cart_discount_code($items = array()) {
795 795
     $invoice = wpinv_get_invoice_cart();
796
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
796
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
797 797
     
798
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
798
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
799 799
 }
800 800
 
801
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
802
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
801
+function wpinv_cart_discount_code($items = array(), $echo = false) {
802
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
803 803
 
804
-    if ( $cart_discount_code != '' ) {
804
+    if ($cart_discount_code != '') {
805 805
         $cart_discount_code = ' (' . $cart_discount_code . ')';
806 806
     }
807 807
     
808
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
808
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
809 809
 
810
-    if ( !$echo ) {
810
+    if (!$echo) {
811 811
         return $discount_code;
812 812
     }
813 813
 
814 814
     echo $discount_code;
815 815
 }
816 816
 
817
-function wpinv_get_cart_discount( $items = array() ) {
817
+function wpinv_get_cart_discount($items = array()) {
818 818
     $invoice = wpinv_get_invoice_cart();
819
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
819
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
820 820
     
821
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
821
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
822 822
 }
823 823
 
824
-function wpinv_cart_discount( $items = array(), $echo = false ) {
825
-    $cart_discount = wpinv_get_cart_discount( $items );
826
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
824
+function wpinv_cart_discount($items = array(), $echo = false) {
825
+    $cart_discount = wpinv_get_cart_discount($items);
826
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
827 827
 
828
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
828
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
829 829
 
830
-    if ( !$echo ) {
830
+    if (!$echo) {
831 831
         return $discount;
832 832
     }
833 833
 
834 834
     echo $discount;
835 835
 }
836 836
 
837
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
838
-    $item = new WPInv_Item( $item_id );
837
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
838
+    $item = new WPInv_Item($item_id);
839 839
     
840
-    return $item->get_fees( $type, $item_id );
840
+    return $item->get_fees($type, $item_id);
841 841
 }
842 842
 
843 843
 function wpinv_get_cart_fee_total() {
844
-    $total  = 0;
844
+    $total = 0;
845 845
     $fees = wpinv_get_cart_fees();
846 846
     
847
-    if ( $fees ) {
848
-        foreach ( $fees as $fee_id => $fee ) {
847
+    if ($fees) {
848
+        foreach ($fees as $fee_id => $fee) {
849 849
             $total += $fee['amount'];
850 850
         }
851 851
     }
852 852
 
853
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
853
+    return apply_filters('wpinv_get_cart_fee_total', $total);
854 854
 }
855 855
 
856 856
 function wpinv_get_cart_fee_tax() {
857 857
     $tax  = 0;
858 858
     $fees = wpinv_get_cart_fees();
859 859
 
860
-    if ( $fees ) {
861
-        foreach ( $fees as $fee_id => $fee ) {
862
-            if( ! empty( $fee['no_tax'] ) ) {
860
+    if ($fees) {
861
+        foreach ($fees as $fee_id => $fee) {
862
+            if (!empty($fee['no_tax'])) {
863 863
                 continue;
864 864
             }
865 865
 
866
-            $tax += wpinv_calculate_tax( $fee['amount'] );
866
+            $tax += wpinv_calculate_tax($fee['amount']);
867 867
         }
868 868
     }
869 869
 
870
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
870
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
871 871
 }
872 872
 
873 873
 function wpinv_cart_has_recurring_item() {
874 874
     $cart_items = wpinv_get_cart_contents();
875 875
     
876
-    if ( empty( $cart_items ) ) {
876
+    if (empty($cart_items)) {
877 877
         return false;
878 878
     }
879 879
     
880 880
     $has_subscription = false;
881
-    foreach( $cart_items as $cart_item ) {
882
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
881
+    foreach ($cart_items as $cart_item) {
882
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
883 883
             $has_subscription = true;
884 884
             break;
885 885
         }
886 886
     }
887 887
     
888
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
888
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
889 889
 }
890 890
 
891 891
 function wpinv_cart_has_free_trial() {
@@ -893,94 +893,94 @@  discard block
 block discarded – undo
893 893
     
894 894
     $free_trial = false;
895 895
     
896
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
896
+    if (!empty($invoice) && $invoice->is_free_trial()) {
897 897
         $free_trial = true;
898 898
     }
899 899
     
900
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
900
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
901 901
 }
902 902
 
903 903
 function wpinv_get_cart_contents() {
904 904
     $cart_details = wpinv_get_cart_details();
905 905
     
906
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
906
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
907 907
 }
908 908
 
909 909
 function wpinv_get_cart_content_details() {
910 910
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
911 911
     $cart_items = wpinv_get_cart_contents();
912 912
     
913
-    if ( empty( $cart_items ) ) {
913
+    if (empty($cart_items)) {
914 914
         return false;
915 915
     }
916 916
     $invoice = wpinv_get_invoice_cart();
917 917
 
918 918
     $details = array();
919
-    $length  = count( $cart_items ) - 1;
919
+    $length  = count($cart_items) - 1;
920 920
     
921
-    if ( empty( $_POST['country'] ) ) {
921
+    if (empty($_POST['country'])) {
922 922
         $_POST['country'] = $invoice->country;
923 923
     }
924
-    if ( !isset( $_POST['state'] ) ) {
924
+    if (!isset($_POST['state'])) {
925 925
         $_POST['state'] = $invoice->state;
926 926
     }
927 927
 
928
-    foreach( $cart_items as $key => $item ) {
929
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
930
-        if ( empty( $item_id ) ) {
928
+    foreach ($cart_items as $key => $item) {
929
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
930
+        if (empty($item_id)) {
931 931
             continue;
932 932
         }
933 933
         
934 934
         $wpi_current_id         = $invoice->ID;
935 935
         $wpi_item_id            = $item_id;
936 936
         
937
-        if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) {
937
+        if (isset($item['custom_price']) && $item['custom_price'] !== '') {
938 938
             $item_price = $item['custom_price'];
939 939
         } else {
940
-            if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) {
940
+            if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) {
941 941
                 $item_price = $item['item_price'];
942 942
             } else {
943
-                $item_price = wpinv_get_item_price( $item_id );
943
+                $item_price = wpinv_get_item_price($item_id);
944 944
             }
945 945
         }
946
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
947
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
948
-        $quantity           = wpinv_get_cart_item_quantity( $item );
949
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
946
+        $discount           = wpinv_get_cart_item_discount_amount($item);
947
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
948
+        $quantity           = wpinv_get_cart_item_quantity($item);
949
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
950 950
         
951 951
         $subtotal           = $item_price * $quantity;
952
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
953
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
954
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
952
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
953
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
954
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
955 955
         
956
-        if ( wpinv_prices_include_tax() ) {
957
-            $subtotal -= wpinv_round_amount( $tax );
956
+        if (wpinv_prices_include_tax()) {
957
+            $subtotal -= wpinv_round_amount($tax);
958 958
         }
959 959
         
960
-        $total              = $subtotal - $discount + $tax;
960
+        $total = $subtotal - $discount + $tax;
961 961
         
962 962
         // Do not allow totals to go negatve
963
-        if( $total < 0 ) {
963
+        if ($total < 0) {
964 964
             $total = 0;
965 965
         }
966 966
         
967
-        $details[ $key ]  = array(
967
+        $details[$key] = array(
968 968
             'id'                => $item_id,
969
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
970
-            'item_price'        => wpinv_round_amount( $item_price ),
971
-            'custom_price'      => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
969
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
970
+            'item_price'        => wpinv_round_amount($item_price),
971
+            'custom_price'      => isset($item['custom_price']) ? $item['custom_price'] : '',
972 972
             'quantity'          => $quantity,
973
-            'discount'          => wpinv_round_amount( $discount ),
974
-            'subtotal'          => wpinv_round_amount( $subtotal ),
975
-            'tax'               => wpinv_round_amount( $tax ),
976
-            'price'             => wpinv_round_amount( $total ),
973
+            'discount'          => wpinv_round_amount($discount),
974
+            'subtotal'          => wpinv_round_amount($subtotal),
975
+            'tax'               => wpinv_round_amount($tax),
976
+            'price'             => wpinv_round_amount($total),
977 977
             'vat_rates_class'   => $tax_class,
978 978
             'vat_rate'          => $tax_rate,
979
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
979
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
980 980
             'fees'              => $fees,
981 981
         );
982 982
         
983
-        if ( $wpinv_is_last_cart_item ) {
983
+        if ($wpinv_is_last_cart_item) {
984 984
             $wpinv_is_last_cart_item   = false;
985 985
             $wpinv_flat_discount_total = 0.00;
986 986
         }
@@ -989,60 +989,60 @@  discard block
 block discarded – undo
989 989
     return $details;
990 990
 }
991 991
 
992
-function wpinv_get_cart_details( $invoice_id = 0 ) {
992
+function wpinv_get_cart_details($invoice_id = 0) {
993 993
     global $ajax_cart_details;
994 994
 
995
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
996
-    $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details;
995
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
996
+    $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details;
997 997
 
998 998
     $invoice_currency = $invoice->currency;
999 999
 
1000
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
1001
-        foreach ( $cart_details as $key => $cart_item ) {
1002
-            $cart_details[ $key ]['currency'] = $invoice_currency;
1000
+    if (!empty($cart_details) && is_array($cart_details)) {
1001
+        foreach ($cart_details as $key => $cart_item) {
1002
+            $cart_details[$key]['currency'] = $invoice_currency;
1003 1003
 
1004
-            if ( ! isset( $cart_item['subtotal'] ) ) {
1005
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
1004
+            if (!isset($cart_item['subtotal'])) {
1005
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
1006 1006
             }
1007 1007
         }
1008 1008
     }
1009 1009
 
1010
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
1010
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
1011 1011
 }
1012 1012
 
1013
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
1014
-    if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) {
1013
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
1014
+    if ('wpi_invoice' != get_post_type($invoice_id)) {
1015 1015
         return;
1016 1016
     }
1017 1017
 
1018
-    $invoice    = wpinv_get_invoice( $invoice_id );
1018
+    $invoice    = wpinv_get_invoice($invoice_id);
1019 1019
     
1020
-    $old_status = wpinv_status_nicename( $old_status );
1021
-    $new_status = wpinv_status_nicename( $new_status );
1020
+    $old_status = wpinv_status_nicename($old_status);
1021
+    $new_status = wpinv_status_nicename($new_status);
1022 1022
 
1023
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
1023
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
1024 1024
     
1025 1025
     // Add note
1026
-    return $invoice->add_note( $status_change, false, false, true );
1026
+    return $invoice->add_note($status_change, false, false, true);
1027 1027
 }
1028
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
1028
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
1029 1029
 
1030
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
1030
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
1031 1031
     global $wpi_has_free_trial;
1032 1032
     
1033 1033
     $wpi_has_free_trial = false;
1034 1034
     
1035
-    if ( $old_status == 'publish' ) {
1035
+    if ($old_status == 'publish') {
1036 1036
         return; // Make sure that payments are only paid once
1037 1037
     }
1038 1038
 
1039 1039
     // Make sure the payment completion is only processed when new status is paid
1040
-    if ( $new_status != 'publish' ) {
1040
+    if ($new_status != 'publish') {
1041 1041
         return;
1042 1042
     }
1043 1043
 
1044
-    $invoice = new WPInv_Invoice( $invoice_id );
1045
-    if ( empty( $invoice ) ) {
1044
+    $invoice = new WPInv_Invoice($invoice_id);
1045
+    if (empty($invoice)) {
1046 1046
         return;
1047 1047
     }
1048 1048
 
@@ -1050,58 +1050,58 @@  discard block
 block discarded – undo
1050 1050
     $completed_date = $invoice->completed_date;
1051 1051
     $cart_details   = $invoice->cart_details;
1052 1052
 
1053
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
1053
+    do_action('wpinv_pre_complete_payment', $invoice_id);
1054 1054
 
1055
-    if ( is_array( $cart_details ) ) {
1055
+    if (is_array($cart_details)) {
1056 1056
         // Increase purchase count and earnings
1057
-        foreach ( $cart_details as $cart_index => $item ) {
1057
+        foreach ($cart_details as $cart_index => $item) {
1058 1058
             // Ensure these actions only run once, ever
1059
-            if ( empty( $completed_date ) ) {
1060
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
1059
+            if (empty($completed_date)) {
1060
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
1061 1061
             }
1062 1062
         }
1063 1063
     }
1064 1064
     
1065 1065
     // Check for discount codes and increment their use counts
1066
-    if ( $discounts = $invoice->get_discounts( true ) ) {
1067
-        if( ! empty( $discounts ) ) {
1068
-            foreach( $discounts as $code ) {
1069
-                wpinv_increase_discount_usage( $code );
1066
+    if ($discounts = $invoice->get_discounts(true)) {
1067
+        if (!empty($discounts)) {
1068
+            foreach ($discounts as $code) {
1069
+                wpinv_increase_discount_usage($code);
1070 1070
             }
1071 1071
         }
1072 1072
     }
1073 1073
     
1074 1074
     // Ensure this action only runs once ever
1075
-    if( empty( $completed_date ) ) {
1075
+    if (empty($completed_date)) {
1076 1076
         // Save the completed date
1077
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
1077
+        $invoice->set('completed_date', current_time('mysql', 0));
1078 1078
         $invoice->save();
1079 1079
 
1080
-        do_action( 'wpinv_complete_payment', $invoice_id );
1080
+        do_action('wpinv_complete_payment', $invoice_id);
1081 1081
     }
1082 1082
 
1083 1083
     // Empty the shopping cart
1084 1084
     wpinv_empty_cart();
1085 1085
 }
1086
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
1086
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
1087 1087
 
1088
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
1089
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
1088
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
1089
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id);
1090 1090
     
1091
-    if ( empty( $invoice ) ) {
1091
+    if (empty($invoice)) {
1092 1092
         return false;
1093 1093
     }
1094 1094
     
1095
-    return $invoice->update_status( $new_status );
1095
+    return $invoice->update_status($new_status);
1096 1096
 }
1097 1097
 
1098
-function wpinv_cart_has_fees( $type = 'all' ) {
1098
+function wpinv_cart_has_fees($type = 'all') {
1099 1099
     return false;
1100 1100
 }
1101 1101
 
1102 1102
 function wpinv_validate_checkout_fields() {    
1103 1103
     // Check if there is $_POST
1104
-    if ( empty( $_POST ) ) {
1104
+    if (empty($_POST)) {
1105 1105
         return false;
1106 1106
     }
1107 1107
     
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
     );
1114 1114
     
1115 1115
     // Validate agree to terms
1116
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1116
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1117 1117
         wpinv_checkout_validate_agree_to_terms();
1118 1118
     }
1119 1119
     
@@ -1129,26 +1129,26 @@  discard block
 block discarded – undo
1129 1129
     
1130 1130
     $invoice = wpinv_get_invoice_cart();
1131 1131
     $has_subscription = $invoice->is_recurring();
1132
-    if ( empty( $invoice ) ) {
1133
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
1132
+    if (empty($invoice)) {
1133
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
1134 1134
         return $gateway;
1135 1135
     }
1136 1136
 
1137 1137
     // Check if a gateway value is present
1138
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
1139
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
1138
+    if (!empty($_REQUEST['wpi-gateway'])) {
1139
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
1140 1140
 
1141
-        if ( $invoice->is_free() ) {
1141
+        if ($invoice->is_free()) {
1142 1142
             $gateway = 'manual';
1143
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
1144
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
1145
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
1146
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) );
1143
+        } elseif (!wpinv_is_gateway_active($gateway)) {
1144
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
1145
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
1146
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing'));
1147 1147
         }
1148 1148
     }
1149 1149
 
1150
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
1151
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
1150
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
1151
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
1152 1152
     }
1153 1153
 
1154 1154
     return $gateway;
@@ -1162,10 +1162,10 @@  discard block
 block discarded – undo
1162 1162
     
1163 1163
     $error = false;
1164 1164
     // If we have discounts, loop through them
1165
-    if ( ! empty( $discounts ) ) {
1166
-        foreach ( $discounts as $discount ) {
1165
+    if (!empty($discounts)) {
1166
+        foreach ($discounts as $discount) {
1167 1167
             // Check if valid
1168
-            if (  !wpinv_is_discount_valid( $discount, (int)$wpi_cart->get_user_id() ) ) {
1168
+            if (!wpinv_is_discount_valid($discount, (int)$wpi_cart->get_user_id())) {
1169 1169
                 // Discount is not valid
1170 1170
                 $error = true;
1171 1171
             }
@@ -1175,20 +1175,20 @@  discard block
 block discarded – undo
1175 1175
         return NULL;
1176 1176
     }
1177 1177
 
1178
-    if ( $error && !wpinv_get_errors() ) {
1179
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
1178
+    if ($error && !wpinv_get_errors()) {
1179
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
1180 1180
     }
1181 1181
 
1182
-    return implode( ',', $discounts );
1182
+    return implode(',', $discounts);
1183 1183
 }
1184 1184
 
1185 1185
 function wpinv_checkout_validate_cc() {
1186 1186
     $card_data = wpinv_checkout_get_cc_info();
1187 1187
 
1188 1188
     // Validate the card zip
1189
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
1190
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
1191
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
1189
+    if (!empty($card_data['wpinv_zip'])) {
1190
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
1191
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
1192 1192
         }
1193 1193
     }
1194 1194
 
@@ -1198,28 +1198,28 @@  discard block
 block discarded – undo
1198 1198
 
1199 1199
 function wpinv_checkout_get_cc_info() {
1200 1200
 	$cc_info = array();
1201
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1202
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1203
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1204
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1205
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1206
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1207
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1208
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1209
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1210
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1201
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
1202
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
1203
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
1204
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
1205
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
1206
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
1207
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
1208
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
1209
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
1210
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
1211 1211
 
1212 1212
 	// Return cc info
1213 1213
 	return $cc_info;
1214 1214
 }
1215 1215
 
1216
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
1216
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
1217 1217
     $ret = false;
1218 1218
 
1219
-    if ( empty( $zip ) || empty( $country_code ) )
1219
+    if (empty($zip) || empty($country_code))
1220 1220
         return $ret;
1221 1221
 
1222
-    $country_code = strtoupper( $country_code );
1222
+    $country_code = strtoupper($country_code);
1223 1223
 
1224 1224
     $zip_regex = array(
1225 1225
         "AD" => "AD\d{3}",
@@ -1379,17 +1379,17 @@  discard block
 block discarded – undo
1379 1379
         "ZM" => "\d{5}"
1380 1380
     );
1381 1381
 
1382
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1382
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
1383 1383
         $ret = true;
1384 1384
 
1385
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1385
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
1386 1386
 }
1387 1387
 
1388 1388
 function wpinv_checkout_validate_agree_to_terms() {
1389 1389
     // Validate agree to terms
1390
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
1390
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
1391 1391
         // User did not agree
1392
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
1392
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
1393 1393
     }
1394 1394
 }
1395 1395
 
@@ -1401,40 +1401,40 @@  discard block
 block discarded – undo
1401 1401
     );
1402 1402
     
1403 1403
     // Verify there is a user_ID
1404
-    if ( $user_ID = (int)$wpi_cart->get_user_id() ) {
1404
+    if ($user_ID = (int)$wpi_cart->get_user_id()) {
1405 1405
         // Get the logged in user data
1406
-        $user_data = get_userdata( $user_ID );
1407
-        $required_fields  = wpinv_checkout_required_fields();
1406
+        $user_data = get_userdata($user_ID);
1407
+        $required_fields = wpinv_checkout_required_fields();
1408 1408
 
1409 1409
         // Loop through required fields and show error messages
1410
-         if ( !empty( $required_fields ) ) {
1411
-            foreach ( $required_fields as $field_name => $value ) {
1412
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1413
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
1410
+         if (!empty($required_fields)) {
1411
+            foreach ($required_fields as $field_name => $value) {
1412
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
1413
+                    wpinv_set_error($value['error_id'], $value['error_message']);
1414 1414
                 }
1415 1415
             }
1416 1416
         }
1417 1417
 
1418 1418
         // Verify data
1419
-        if ( $user_data ) {
1419
+        if ($user_data) {
1420 1420
             // Collected logged in user data
1421 1421
             $valid_user_data = array(
1422 1422
                 'user_id'     => $user_ID,
1423
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
1424
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
1425
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
1423
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
1424
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
1425
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
1426 1426
             );
1427 1427
 
1428
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
1429
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
1428
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
1429
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
1430 1430
             }
1431 1431
         } else {
1432 1432
             // Set invalid user error
1433
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
1433
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
1434 1434
         }
1435 1435
     } else {
1436 1436
         // Set invalid user error
1437
-        wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) );
1437
+        wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing'));
1438 1438
     }
1439 1439
 
1440 1440
     // Return user data
@@ -1446,30 +1446,30 @@  discard block
 block discarded – undo
1446 1446
 
1447 1447
     $data = array();
1448 1448
     
1449
-    if ( is_user_logged_in() ) {
1450
-        if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) {
1449
+    if (is_user_logged_in()) {
1450
+        if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id())) {
1451 1451
             $data['user_id'] = (int)get_current_user_id();
1452 1452
         } else {
1453
-            wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) );
1453
+            wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing'));
1454 1454
         }
1455 1455
     } else {
1456 1456
         // If guest checkout allowed
1457
-        if ( !wpinv_require_login_to_checkout() ) {
1457
+        if (!wpinv_require_login_to_checkout()) {
1458 1458
             $data['user_id'] = 0;
1459 1459
         } else {
1460
-            wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) );
1460
+            wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing'));
1461 1461
         }
1462 1462
     }
1463 1463
 
1464 1464
     return $data;
1465 1465
 }
1466 1466
 
1467
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
1467
+function wpinv_checkout_form_get_user($valid_data = array()) {
1468 1468
     // Initialize user
1469 1469
     $user    = false;
1470
-    $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
1470
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1471 1471
 
1472
-    if ( empty( $valid_data['current_user'] ) ) {
1472
+    if (empty($valid_data['current_user'])) {
1473 1473
         $user = false;
1474 1474
     } else {
1475 1475
         // Set the valid invoice user
@@ -1477,7 +1477,7 @@  discard block
 block discarded – undo
1477 1477
     }
1478 1478
 
1479 1479
     // Verify invoice have an user
1480
-    if ( false === $user || empty( $user ) ) {
1480
+    if (false === $user || empty($user)) {
1481 1481
         return false;
1482 1482
     }
1483 1483
 
@@ -1494,11 +1494,11 @@  discard block
 block discarded – undo
1494 1494
         'zip',
1495 1495
     );
1496 1496
     
1497
-    foreach ( $address_fields as $field ) {
1498
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1497
+    foreach ($address_fields as $field) {
1498
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1499 1499
         
1500
-        if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $user['user_id'] ) {
1501
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1500
+        if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $user['user_id']) {
1501
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1502 1502
         }
1503 1503
     }
1504 1504
 
@@ -1506,28 +1506,28 @@  discard block
 block discarded – undo
1506 1506
     return $user;
1507 1507
 }
1508 1508
 
1509
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1509
+function wpinv_set_checkout_session($invoice_data = array()) {
1510 1510
     global $wpi_session;
1511 1511
     
1512
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1512
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1513 1513
 }
1514 1514
 
1515 1515
 function wpinv_get_checkout_session() {
1516 1516
 	global $wpi_session;
1517 1517
     
1518
-    return $wpi_session->get( 'wpinv_checkout' );
1518
+    return $wpi_session->get('wpinv_checkout');
1519 1519
 }
1520 1520
 
1521 1521
 function wpinv_empty_cart() {
1522 1522
     global $wpi_session;
1523 1523
 
1524 1524
     // Remove cart contents
1525
-    $wpi_session->set( 'wpinv_checkout', NULL );
1525
+    $wpi_session->set('wpinv_checkout', NULL);
1526 1526
 
1527 1527
     // Remove all cart fees
1528
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1528
+    $wpi_session->set('wpi_cart_fees', NULL);
1529 1529
 
1530
-    do_action( 'wpinv_empty_cart' );
1530
+    do_action('wpinv_empty_cart');
1531 1531
 }
1532 1532
 
1533 1533
 function wpinv_process_checkout() {
@@ -1540,42 +1540,42 @@  discard block
 block discarded – undo
1540 1540
     
1541 1541
     $wpi_checkout_id = $invoice->ID;
1542 1542
     
1543
-    do_action( 'wpinv_pre_process_checkout' );
1543
+    do_action('wpinv_pre_process_checkout');
1544 1544
     
1545
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1545
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1546 1546
         $valid_data = false;
1547
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1547
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1548 1548
     } else {
1549 1549
         // Validate the form $_POST data
1550 1550
         $valid_data = wpinv_validate_checkout_fields();
1551 1551
         
1552 1552
         // Allow themes and plugins to hook to errors
1553
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1553
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1554 1554
     }
1555 1555
     
1556
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1556
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1557 1557
     
1558 1558
     // Validate the user
1559
-    $user = wpinv_checkout_form_get_user( $valid_data );
1559
+    $user = wpinv_checkout_form_get_user($valid_data);
1560 1560
 
1561 1561
     // Let extensions validate fields after user is logged in if user has used login/registration form
1562
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1562
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1563 1563
     
1564
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1565
-        if ( $is_ajax ) {
1566
-            do_action( 'wpinv_ajax_checkout_errors' );
1564
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1565
+        if ($is_ajax) {
1566
+            do_action('wpinv_ajax_checkout_errors');
1567 1567
             die();
1568 1568
         } else {
1569 1569
             return false;
1570 1570
         }
1571 1571
     }
1572 1572
 
1573
-    if ( $is_ajax ) {
1573
+    if ($is_ajax) {
1574 1574
         // Save address fields.
1575
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1576
-        foreach ( $address_fields as $field ) {
1577
-            if ( isset( $user[$field] ) ) {
1578
-                $invoice->set( $field, $user[$field] );
1575
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1576
+        foreach ($address_fields as $field) {
1577
+            if (isset($user[$field])) {
1578
+                $invoice->set($field, $user[$field]);
1579 1579
             }
1580 1580
             
1581 1581
             $invoice->save();
@@ -1583,15 +1583,15 @@  discard block
 block discarded – undo
1583 1583
 
1584 1584
         $response['success']            = true;
1585 1585
         $response['data']['subtotal']   = $invoice->get_subtotal();
1586
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1586
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1587 1587
         $response['data']['discount']   = $invoice->get_discount();
1588
-        $response['data']['discountf']  = $invoice->get_discount( true );
1588
+        $response['data']['discountf']  = $invoice->get_discount(true);
1589 1589
         $response['data']['tax']        = $invoice->get_tax();
1590
-        $response['data']['taxf']       = $invoice->get_tax( true );
1590
+        $response['data']['taxf']       = $invoice->get_tax(true);
1591 1591
         $response['data']['total']      = $invoice->get_total();
1592
-        $response['data']['totalf']     = $invoice->get_total( true );
1592
+        $response['data']['totalf']     = $invoice->get_total(true);
1593 1593
         
1594
-        wp_send_json( $response );
1594
+        wp_send_json($response);
1595 1595
     }
1596 1596
     
1597 1597
     $user_info = array(
@@ -1613,42 +1613,42 @@  discard block
 block discarded – undo
1613 1613
     
1614 1614
     // Setup invoice information
1615 1615
     $invoice_data = array(
1616
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1616
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1617 1617
         'items'             => $cart_items,
1618 1618
         'cart_discounts'    => $discounts,
1619
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1620
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1621
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1622
-        'tax'               => wpinv_get_cart_tax( $cart_items ),               // Taxed amount
1623
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1619
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1620
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1621
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1622
+        'tax'               => wpinv_get_cart_tax($cart_items), // Taxed amount
1623
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1624 1624
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1625 1625
         'user_email'        => $user['email'],
1626
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1627
-        'user_info'         => stripslashes_deep( $user_info ),
1626
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1627
+        'user_info'         => stripslashes_deep($user_info),
1628 1628
         'post_data'         => $_POST,
1629 1629
         'cart_details'      => $cart_items,
1630 1630
         'gateway'           => $valid_data['gateway'],
1631 1631
         'card_info'         => $valid_data['cc_info']
1632 1632
     );
1633 1633
     
1634
-    $vat_info   = $wpinv_euvat->current_vat_data();
1635
-    if ( is_array( $vat_info ) ) {
1634
+    $vat_info = $wpinv_euvat->current_vat_data();
1635
+    if (is_array($vat_info)) {
1636 1636
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1637 1637
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1638
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1638
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1639 1639
 
1640 1640
         // Add the VAT rate to each item in the cart
1641
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1641
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1642 1642
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1643
-            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 );
1643
+            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4);
1644 1644
         }
1645 1645
     }
1646 1646
     
1647 1647
     // Save vat fields.
1648
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1649
-    foreach ( $address_fields as $field ) {
1650
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1651
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1648
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1649
+    foreach ($address_fields as $field) {
1650
+        if (isset($invoice_data['user_info'][$field])) {
1651
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1652 1652
         }
1653 1653
         
1654 1654
         $invoice->save();
@@ -1658,49 +1658,49 @@  discard block
 block discarded – undo
1658 1658
     $valid_data['user'] = $user;
1659 1659
     
1660 1660
     // Allow themes and plugins to hook before the gateway
1661
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1661
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1662 1662
     
1663 1663
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1664
-    if ( !$invoice_data['price'] ) {
1664
+    if (!$invoice_data['price']) {
1665 1665
         // Revert to manual
1666 1666
         $invoice_data['gateway'] = 'manual';
1667 1667
         $_POST['wpi-gateway'] = 'manual';
1668 1668
     }
1669 1669
     
1670 1670
     // Allow the invoice data to be modified before it is sent to the gateway
1671
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1671
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1672 1672
     
1673 1673
     // Setup the data we're storing in the purchase session
1674 1674
     $session_data = $invoice_data;
1675 1675
     // Make sure credit card numbers are never stored in sessions
1676
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1677
-        unset( $session_data['card_info']['card_number'] );
1676
+    if (!empty($session_data['card_info']['card_number'])) {
1677
+        unset($session_data['card_info']['card_number']);
1678 1678
     }
1679 1679
     
1680 1680
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1681
-    wpinv_set_checkout_session( $invoice_data );
1681
+    wpinv_set_checkout_session($invoice_data);
1682 1682
     
1683 1683
     // Set gateway
1684
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1685
-    $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) );
1686
-    $invoice->update_meta( '_wpinv_checkout', true );
1684
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1685
+    $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'));
1686
+    $invoice->update_meta('_wpinv_checkout', true);
1687 1687
     
1688
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1688
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1689 1689
 
1690 1690
     // Send info to the gateway for payment processing
1691
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1691
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1692 1692
     die();
1693 1693
 }
1694
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1694
+add_action('wpinv_payment', 'wpinv_process_checkout');
1695 1695
 
1696
-function wpinv_get_invoices( $args ) {
1697
-    $args = wp_parse_args( $args, array(
1698
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1696
+function wpinv_get_invoices($args) {
1697
+    $args = wp_parse_args($args, array(
1698
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1699 1699
         'type'     => 'wpi_invoice',
1700 1700
         'parent'   => null,
1701 1701
         'user'     => null,
1702 1702
         'email'    => '',
1703
-        'limit'    => get_option( 'posts_per_page' ),
1703
+        'limit'    => get_option('posts_per_page'),
1704 1704
         'offset'   => null,
1705 1705
         'page'     => 1,
1706 1706
         'exclude'  => array(),
@@ -1708,7 +1708,7 @@  discard block
 block discarded – undo
1708 1708
         'order'    => 'DESC',
1709 1709
         'return'   => 'objects',
1710 1710
         'paginate' => false,
1711
-    ) );
1711
+    ));
1712 1712
     
1713 1713
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1714 1714
     $map_legacy = array(
@@ -1721,18 +1721,18 @@  discard block
 block discarded – undo
1721 1721
         'paged'          => 'page',
1722 1722
     );
1723 1723
 
1724
-    foreach ( $map_legacy as $from => $to ) {
1725
-        if ( isset( $args[ $from ] ) ) {
1726
-            $args[ $to ] = $args[ $from ];
1724
+    foreach ($map_legacy as $from => $to) {
1725
+        if (isset($args[$from])) {
1726
+            $args[$to] = $args[$from];
1727 1727
         }
1728 1728
     }
1729 1729
 
1730
-    if ( get_query_var( 'paged' ) )
1730
+    if (get_query_var('paged'))
1731 1731
         $args['page'] = get_query_var('paged');
1732
-    else if ( get_query_var( 'page' ) )
1733
-        $args['page'] = get_query_var( 'page' );
1734
-    else if ( !empty( $args[ 'page' ] ) )
1735
-        $args['page'] = $args[ 'page' ];
1732
+    else if (get_query_var('page'))
1733
+        $args['page'] = get_query_var('page');
1734
+    else if (!empty($args['page']))
1735
+        $args['page'] = $args['page'];
1736 1736
     else
1737 1737
         $args['page'] = 1;
1738 1738
 
@@ -1745,47 +1745,47 @@  discard block
 block discarded – undo
1745 1745
         'post_status'    => $args['status'],
1746 1746
         'posts_per_page' => $args['limit'],
1747 1747
         'meta_query'     => array(),
1748
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1748
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1749 1749
         'fields'         => 'ids',
1750 1750
         'orderby'        => $args['orderby'],
1751 1751
         'order'          => $args['order'],
1752 1752
     );
1753 1753
     
1754
-    if ( !empty( $args['user'] ) ) {
1755
-        $wp_query_args['author'] = absint( $args['user'] );
1754
+    if (!empty($args['user'])) {
1755
+        $wp_query_args['author'] = absint($args['user']);
1756 1756
     }
1757 1757
 
1758
-    if ( ! is_null( $args['parent'] ) ) {
1759
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1758
+    if (!is_null($args['parent'])) {
1759
+        $wp_query_args['post_parent'] = absint($args['parent']);
1760 1760
     }
1761 1761
 
1762
-    if ( ! is_null( $args['offset'] ) ) {
1763
-        $wp_query_args['offset'] = absint( $args['offset'] );
1762
+    if (!is_null($args['offset'])) {
1763
+        $wp_query_args['offset'] = absint($args['offset']);
1764 1764
     } else {
1765
-        $wp_query_args['paged'] = absint( $args['page'] );
1765
+        $wp_query_args['paged'] = absint($args['page']);
1766 1766
     }
1767 1767
 
1768
-    if ( ! empty( $args['exclude'] ) ) {
1769
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1768
+    if (!empty($args['exclude'])) {
1769
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1770 1770
     }
1771 1771
 
1772
-    if ( ! $args['paginate' ] ) {
1772
+    if (!$args['paginate']) {
1773 1773
         $wp_query_args['no_found_rows'] = true;
1774 1774
     }
1775 1775
 
1776 1776
     // Get results.
1777
-    $invoices = new WP_Query( $wp_query_args );
1777
+    $invoices = new WP_Query($wp_query_args);
1778 1778
 
1779
-    if ( 'objects' === $args['return'] ) {
1780
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1781
-    } elseif ( 'self' === $args['return'] ) {
1779
+    if ('objects' === $args['return']) {
1780
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1781
+    } elseif ('self' === $args['return']) {
1782 1782
         return $invoices;
1783 1783
     } else {
1784 1784
         $return = $invoices->posts;
1785 1785
     }
1786 1786
 
1787
-    if ( $args['paginate' ] ) {
1788
-        return (object) array(
1787
+    if ($args['paginate']) {
1788
+        return (object)array(
1789 1789
             'invoices'      => $return,
1790 1790
             'total'         => $invoices->found_posts,
1791 1791
             'max_num_pages' => $invoices->max_num_pages,
@@ -1797,22 +1797,22 @@  discard block
 block discarded – undo
1797 1797
 
1798 1798
 function wpinv_get_user_invoices_columns() {
1799 1799
     $columns = array(
1800
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1801
-            'created-date'    => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ),
1802
-            'payment-date'    => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ),
1803
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1804
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1805
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1800
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1801
+            'created-date'    => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'),
1802
+            'payment-date'    => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'),
1803
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1804
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1805
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1806 1806
         );
1807 1807
 
1808
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1808
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1809 1809
 }
1810 1810
 
1811
-function wpinv_payment_receipt( $atts, $content = null ) {
1811
+function wpinv_payment_receipt($atts, $content = null) {
1812 1812
     global $wpinv_receipt_args;
1813 1813
 
1814
-    $wpinv_receipt_args = shortcode_atts( array(
1815
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1814
+    $wpinv_receipt_args = shortcode_atts(array(
1815
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1816 1816
         'price'           => true,
1817 1817
         'discount'        => true,
1818 1818
         'items'           => true,
@@ -1821,195 +1821,195 @@  discard block
 block discarded – undo
1821 1821
         'invoice_key'     => false,
1822 1822
         'payment_method'  => true,
1823 1823
         'invoice_id'      => true
1824
-    ), $atts, 'wpinv_receipt' );
1824
+    ), $atts, 'wpinv_receipt');
1825 1825
 
1826 1826
     $session = wpinv_get_checkout_session();
1827
-    if ( isset( $_GET['invoice_key'] ) ) {
1828
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1829
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1827
+    if (isset($_GET['invoice_key'])) {
1828
+        $invoice_key = urldecode($_GET['invoice_key']);
1829
+    } else if ($session && isset($session['invoice_key'])) {
1830 1830
         $invoice_key = $session['invoice_key'];
1831
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1831
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1832 1832
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1833
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1834
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1833
+    } else if (isset($_GET['invoice-id'])) {
1834
+        $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']);
1835 1835
     }
1836 1836
 
1837 1837
     // No key found
1838
-    if ( ! isset( $invoice_key ) ) {
1838
+    if (!isset($invoice_key)) {
1839 1839
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1840 1840
     }
1841 1841
 
1842
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1843
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1844
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1842
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1843
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1844
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1845 1845
         $invoice_id     = (int)$_GET['invoice-id'];
1846
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1846
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1847 1847
     }
1848 1848
 
1849 1849
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1850
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1850
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1851 1851
         // login redirect
1852
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1852
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1853 1853
     }
1854 1854
 
1855
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1855
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1856 1856
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1857 1857
     }
1858 1858
 
1859 1859
     ob_start();
1860 1860
 
1861
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1861
+    wpinv_get_template_part('wpinv-invoice-receipt');
1862 1862
 
1863 1863
     $display = ob_get_clean();
1864 1864
 
1865 1865
     return $display;
1866 1866
 }
1867 1867
 
1868
-function wpinv_get_invoice_id_by_key( $key ) {
1868
+function wpinv_get_invoice_id_by_key($key) {
1869 1869
 	global $wpdb;
1870 1870
 
1871
-	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1871
+	$invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key));
1872 1872
 
1873
-	if ( $invoice_id != NULL )
1873
+	if ($invoice_id != NULL)
1874 1874
 		return $invoice_id;
1875 1875
 
1876 1876
 	return 0;
1877 1877
 }
1878 1878
 
1879
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1879
+function wpinv_can_view_receipt($invoice_key = '') {
1880 1880
 	$return = false;
1881 1881
 
1882
-	if ( empty( $invoice_key ) ) {
1882
+	if (empty($invoice_key)) {
1883 1883
 		return $return;
1884 1884
 	}
1885 1885
 
1886 1886
 	global $wpinv_receipt_args;
1887 1887
 
1888
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1889
-	if ( isset( $_GET['invoice-id'] ) ) {
1890
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1888
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1889
+	if (isset($_GET['invoice-id'])) {
1890
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0;
1891 1891
 	}
1892 1892
 
1893
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
1893
+	if (empty($wpinv_receipt_args['id'])) {
1894 1894
 		return $return;
1895 1895
 	}
1896 1896
 
1897
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1898
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1897
+	$invoice = wpinv_get_invoice($wpinv_receipt_args['id']);
1898
+	if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) {
1899 1899
 		return $return;
1900 1900
 	}
1901 1901
 
1902
-	if ( is_user_logged_in() ) {
1903
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1902
+	if (is_user_logged_in()) {
1903
+		if ((int)$invoice->get_user_id() === (int)get_current_user_id()) {
1904 1904
 			$return = true;
1905 1905
 		}
1906 1906
 	}
1907 1907
 
1908 1908
 	$session = wpinv_get_checkout_session();
1909
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1910
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1909
+	if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) {
1910
+		$check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key'];
1911 1911
 
1912
-		if ( wpinv_require_login_to_checkout() ) {
1912
+		if (wpinv_require_login_to_checkout()) {
1913 1913
 			$return = $return && $check_key === $invoice_key;
1914 1914
 		} else {
1915 1915
 			$return = $check_key === $invoice_key;
1916 1916
 		}
1917 1917
 	}
1918 1918
 
1919
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1919
+	return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
1920 1920
 }
1921 1921
 
1922 1922
 function wpinv_pay_for_invoice() {
1923 1923
     global $wpinv_euvat;
1924 1924
     
1925
-    if ( isset( $_GET['invoice_key'] ) ) {
1925
+    if (isset($_GET['invoice_key'])) {
1926 1926
         $checkout_uri   = wpinv_get_checkout_uri();
1927
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
1927
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
1928 1928
         
1929
-        if ( empty( $invoice_key ) ) {
1930
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
1931
-            wp_redirect( $checkout_uri );
1929
+        if (empty($invoice_key)) {
1930
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
1931
+            wp_redirect($checkout_uri);
1932 1932
             wpinv_die();
1933 1933
         }
1934 1934
         
1935
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
1935
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
1936 1936
 
1937
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1938
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
1939
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1937
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1938
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
1939
+        if ($user_can_view && isset($_GET['invoice-id'])) {
1940 1940
             $invoice_id     = (int)$_GET['invoice-id'];
1941
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1941
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1942 1942
         }
1943 1943
         
1944
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
1945
-            if ( $invoice->needs_payment() ) {
1944
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
1945
+            if ($invoice->needs_payment()) {
1946 1946
                 $data                   = array();
1947 1947
                 $data['invoice_id']     = $invoice_id;
1948
-                $data['cart_discounts'] = $invoice->get_discounts( true );
1948
+                $data['cart_discounts'] = $invoice->get_discounts(true);
1949 1949
                 
1950
-                wpinv_set_checkout_session( $data );
1950
+                wpinv_set_checkout_session($data);
1951 1951
                 
1952
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1952
+                if (wpinv_get_option('vat_ip_country_default')) {
1953 1953
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
1954 1954
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
1955 1955
                     
1956
-                    wpinv_recalculate_tax( true );
1956
+                    wpinv_recalculate_tax(true);
1957 1957
                 }
1958 1958
                 
1959 1959
             } else {
1960 1960
                 $checkout_uri = $invoice->get_view_url();
1961 1961
             }
1962 1962
         } else {
1963
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
1963
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
1964 1964
             
1965
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
1965
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
1966 1966
         }
1967 1967
         
1968
-        wp_redirect( $checkout_uri );
1968
+        wp_redirect($checkout_uri);
1969 1969
         wpinv_die();
1970 1970
     }
1971 1971
 }
1972
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
1972
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
1973 1973
 
1974
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
1975
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
1976
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
1974
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
1975
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
1976
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
1977 1977
             $user_id = $invoice->get_user_id();
1978
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
1978
+            $secret = sanitize_text_field($_GET['_wpipay']);
1979 1979
             
1980
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
1981
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
1980
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
1981
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
1982 1982
                 
1983
-                wpinv_guest_redirect( $redirect_to, $user_id );
1983
+                wpinv_guest_redirect($redirect_to, $user_id);
1984 1984
                 wpinv_die();
1985 1985
             }
1986 1986
         }
1987 1987
     }
1988 1988
 }
1989
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
1989
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
1990 1990
 
1991
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
1992
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
1991
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
1992
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
1993 1993
     
1994
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
1994
+    if (empty($invoice_id) && $invoice_id > 0) {
1995 1995
         return false;
1996 1996
     }
1997 1997
     
1998
-    if ( empty( $transaction_id ) ) {
1998
+    if (empty($transaction_id)) {
1999 1999
         $transaction_id = $invoice_id;
2000 2000
     }
2001 2001
 
2002
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
2002
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
2003 2003
     
2004
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
2004
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
2005 2005
 }
2006 2006
 
2007
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
2008
-    if ( empty( $status_display ) ) {
2009
-        $status_display = wpinv_status_nicename( $status );
2007
+function wpinv_invoice_status_label($status, $status_display = '') {
2008
+    if (empty($status_display)) {
2009
+        $status_display = wpinv_status_nicename($status);
2010 2010
     }
2011 2011
     
2012
-    switch ( $status ) {
2012
+    switch ($status) {
2013 2013
         case 'publish' :
2014 2014
         case 'wpi-renewal' :
2015 2015
             $class = 'label-success';
@@ -2034,243 +2034,243 @@  discard block
 block discarded – undo
2034 2034
     
2035 2035
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
2036 2036
     
2037
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
2037
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
2038 2038
 }
2039 2039
 
2040
-function wpinv_format_invoice_number( $number, $type = '' ) {
2041
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
2042
-    if ( null !== $check ) {
2040
+function wpinv_format_invoice_number($number, $type = '') {
2041
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
2042
+    if (null !== $check) {
2043 2043
         return $check;
2044 2044
     }
2045 2045
 
2046
-    if ( !empty( $number ) && !is_numeric( $number ) ) {
2046
+    if (!empty($number) && !is_numeric($number)) {
2047 2047
         return $number;
2048 2048
     }
2049 2049
 
2050
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
2051
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2052
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2050
+    $padd = wpinv_get_option('invoice_number_padd');
2051
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2052
+    $postfix = wpinv_get_option('invoice_number_postfix');
2053 2053
     
2054
-    $padd = absint( $padd );
2055
-    $formatted_number = absint( $number );
2054
+    $padd = absint($padd);
2055
+    $formatted_number = absint($number);
2056 2056
     
2057
-    if ( $padd > 0 ) {
2058
-        $formatted_number = zeroise( $formatted_number, $padd );
2057
+    if ($padd > 0) {
2058
+        $formatted_number = zeroise($formatted_number, $padd);
2059 2059
     }    
2060 2060
 
2061 2061
     $formatted_number = $prefix . $formatted_number . $postfix;
2062 2062
 
2063
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
2063
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
2064 2064
 }
2065 2065
 
2066
-function wpinv_get_next_invoice_number( $type = '' ) {
2067
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
2068
-    if ( null !== $check ) {
2066
+function wpinv_get_next_invoice_number($type = '') {
2067
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
2068
+    if (null !== $check) {
2069 2069
         return $check;
2070 2070
     }
2071 2071
     
2072
-    if ( !wpinv_sequential_number_active() ) {
2072
+    if (!wpinv_sequential_number_active()) {
2073 2073
         return false;
2074 2074
     }
2075 2075
 
2076
-    $number = $last_number = get_option( 'wpinv_last_invoice_number' );
2077
-    $start  = wpinv_get_option( 'invoice_sequence_start' );
2078
-    if ( !absint( $start ) > 0 ) {
2076
+    $number = $last_number = get_option('wpinv_last_invoice_number');
2077
+    $start  = wpinv_get_option('invoice_sequence_start');
2078
+    if (!absint($start) > 0) {
2079 2079
         $start = 1;
2080 2080
     }
2081 2081
     $increment_number = true;
2082 2082
     $save_number = false;
2083 2083
 
2084
-    if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) {
2085
-        $number = wpinv_clean_invoice_number( $number );
2084
+    if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) {
2085
+        $number = wpinv_clean_invoice_number($number);
2086 2086
     }
2087 2087
 
2088
-    if ( empty( $number ) ) {
2089
-        if ( !( $last_number === 0 || $last_number === '0' ) ) {
2090
-            $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true ) ) ) );
2088
+    if (empty($number)) {
2089
+        if (!($last_number === 0 || $last_number === '0')) {
2090
+            $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true))));
2091 2091
 
2092
-            if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) {
2093
-                if ( is_numeric( $invoice_number ) ) {
2092
+            if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) {
2093
+                if (is_numeric($invoice_number)) {
2094 2094
                     $number = $invoice_number;
2095 2095
                 } else {
2096
-                    $number = wpinv_clean_invoice_number( $invoice_number );
2096
+                    $number = wpinv_clean_invoice_number($invoice_number);
2097 2097
                 }
2098 2098
             }
2099 2099
 
2100
-            if ( empty( $number ) ) {
2100
+            if (empty($number)) {
2101 2101
                 $increment_number = false;
2102 2102
                 $number = $start;
2103
-                $save_number = ( $number - 1 );
2103
+                $save_number = ($number - 1);
2104 2104
             } else {
2105 2105
                 $save_number = $number;
2106 2106
             }
2107 2107
         }
2108 2108
     }
2109 2109
 
2110
-    if ( $start > $number ) {
2110
+    if ($start > $number) {
2111 2111
         $increment_number = false;
2112 2112
         $number = $start;
2113
-        $save_number = ( $number - 1 );
2113
+        $save_number = ($number - 1);
2114 2114
     }
2115 2115
 
2116
-    if ( $save_number !== false ) {
2117
-        update_option( 'wpinv_last_invoice_number', $save_number );
2116
+    if ($save_number !== false) {
2117
+        update_option('wpinv_last_invoice_number', $save_number);
2118 2118
     }
2119 2119
     
2120
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
2120
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
2121 2121
 
2122
-    if ( $increment_number ) {
2122
+    if ($increment_number) {
2123 2123
         $number++;
2124 2124
     }
2125 2125
 
2126
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
2126
+    return apply_filters('wpinv_get_next_invoice_number', $number);
2127 2127
 }
2128 2128
 
2129
-function wpinv_clean_invoice_number( $number, $type = '' ) {
2130
-    $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type );
2131
-    if ( null !== $check ) {
2129
+function wpinv_clean_invoice_number($number, $type = '') {
2130
+    $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type);
2131
+    if (null !== $check) {
2132 2132
         return $check;
2133 2133
     }
2134 2134
     
2135
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2136
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2135
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2136
+    $postfix = wpinv_get_option('invoice_number_postfix');
2137 2137
 
2138
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
2138
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
2139 2139
 
2140
-    $length      = strlen( $number );
2141
-    $postfix_pos = strrpos( $number, $postfix );
2140
+    $length      = strlen($number);
2141
+    $postfix_pos = strrpos($number, $postfix);
2142 2142
     
2143
-    if ( false !== $postfix_pos ) {
2144
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
2143
+    if (false !== $postfix_pos) {
2144
+        $number = substr_replace($number, '', $postfix_pos, $length);
2145 2145
     }
2146 2146
 
2147
-    $number = intval( $number );
2147
+    $number = intval($number);
2148 2148
 
2149
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
2149
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
2150 2150
 }
2151 2151
 
2152
-function wpinv_save_number_post_saved( $post_ID, $post, $update ) {
2152
+function wpinv_save_number_post_saved($post_ID, $post, $update) {
2153 2153
     global $wpdb;
2154 2154
 
2155
-    if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) {
2156
-        wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type );
2155
+    if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) {
2156
+        wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type);
2157 2157
     }
2158 2158
 
2159
-    if ( !$update ) {
2160
-        $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) );
2161
-        clean_post_cache( $post_ID );
2159
+    if (!$update) {
2160
+        $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID));
2161
+        clean_post_cache($post_ID);
2162 2162
     }
2163 2163
 }
2164
-add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 );
2164
+add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3);
2165 2165
 
2166
-function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) {
2167
-    if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) {
2168
-        wpinv_update_invoice_number( $post_ID, true, $post_after->post_type );
2166
+function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) {
2167
+    if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) {
2168
+        wpinv_update_invoice_number($post_ID, true, $post_after->post_type);
2169 2169
     }
2170 2170
 }
2171
-add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 );
2171
+add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3);
2172 2172
 
2173
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) {
2173
+function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') {
2174 2174
     global $wpdb;
2175 2175
     
2176
-    $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type );
2177
-    if ( null !== $check ) {
2176
+    $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type);
2177
+    if (null !== $check) {
2178 2178
         return $check;
2179 2179
     }
2180 2180
 
2181
-    if ( wpinv_sequential_number_active() ) {
2181
+    if (wpinv_sequential_number_active()) {
2182 2182
         $number = wpinv_get_next_invoice_number();
2183 2183
 
2184
-        if ( $save_sequential ) {
2185
-            update_option( 'wpinv_last_invoice_number', $number );
2184
+        if ($save_sequential) {
2185
+            update_option('wpinv_last_invoice_number', $number);
2186 2186
         }
2187 2187
     } else {
2188 2188
         $number = $post_ID;
2189 2189
     }
2190 2190
 
2191
-    $number = wpinv_format_invoice_number( $number );
2191
+    $number = wpinv_format_invoice_number($number);
2192 2192
 
2193
-    update_post_meta( $post_ID, '_wpinv_number', $number );
2193
+    update_post_meta($post_ID, '_wpinv_number', $number);
2194 2194
 
2195
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
2195
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
2196 2196
 
2197
-    clean_post_cache( $post_ID );
2197
+    clean_post_cache($post_ID);
2198 2198
 
2199 2199
     return $number;
2200 2200
 }
2201 2201
 
2202
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
2203
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
2202
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
2203
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
2204 2204
 }
2205 2205
 
2206
-function wpinv_generate_post_name( $post_ID ) {
2207
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
2208
-    $post_name = sanitize_title( $prefix . $post_ID );
2206
+function wpinv_generate_post_name($post_ID) {
2207
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
2208
+    $post_name = sanitize_title($prefix . $post_ID);
2209 2209
 
2210
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
2210
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
2211 2211
 }
2212 2212
 
2213
-function wpinv_is_invoice_viewed( $invoice_id ) {
2214
-    if ( empty( $invoice_id ) ) {
2213
+function wpinv_is_invoice_viewed($invoice_id) {
2214
+    if (empty($invoice_id)) {
2215 2215
         return false;
2216 2216
     }
2217 2217
 
2218
-    $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true );
2218
+    $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true);
2219 2219
 
2220
-    if ( isset($viewed_meta) && 1 == $viewed_meta ) {
2220
+    if (isset($viewed_meta) && 1 == $viewed_meta) {
2221 2221
         $is_viewed = true;
2222 2222
     } else {
2223 2223
         $is_viewed = false;
2224 2224
     }
2225 2225
 
2226
-    return apply_filters( 'wpinv_is_invoice_viewed', $is_viewed, $invoice_id );
2226
+    return apply_filters('wpinv_is_invoice_viewed', $is_viewed, $invoice_id);
2227 2227
 }
2228 2228
 
2229 2229
 function wpinv_mark_invoice_viewed() {
2230 2230
 
2231
-    if ( isset( $_GET['invoice_key'] ) ) {
2231
+    if (isset($_GET['invoice_key'])) {
2232 2232
         $invoice_key = urldecode($_GET['invoice_key']);
2233 2233
 
2234 2234
         $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2235 2235
         $invoice = new WPInv_Invoice($invoice_id);
2236 2236
 
2237
-        if(!$invoice_id){
2237
+        if (!$invoice_id) {
2238 2238
             return;
2239 2239
         }
2240 2240
 
2241
-        if( is_user_logged_in()){
2241
+        if (is_user_logged_in()) {
2242 2242
             $current_user = wp_get_current_user();
2243
-            if(!current_user_can('administrator') && $current_user->user_email == $invoice->get_email()){
2244
-                update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2243
+            if (!current_user_can('administrator') && $current_user->user_email == $invoice->get_email()) {
2244
+                update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2245 2245
             }
2246 2246
         } else {
2247
-            update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2247
+            update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2248 2248
         }
2249 2249
     }
2250 2250
 
2251 2251
 }
2252
-add_action( 'init', 'wpinv_mark_invoice_viewed' );
2252
+add_action('init', 'wpinv_mark_invoice_viewed');
2253 2253
 
2254
-function wpinv_get_subscription( $invoice ) {
2255
-    if ( empty( $invoice ) ) {
2254
+function wpinv_get_subscription($invoice) {
2255
+    if (empty($invoice)) {
2256 2256
         return false;
2257 2257
     }
2258 2258
     
2259
-    if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
2260
-        $invoice = wpinv_get_invoice( $invoice );
2259
+    if (!is_object($invoice) && is_scalar($invoice)) {
2260
+        $invoice = wpinv_get_invoice($invoice);
2261 2261
     }
2262 2262
     
2263
-    if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) {
2263
+    if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) {
2264 2264
         return false;
2265 2265
     }
2266 2266
     
2267
-    $invoice_id = ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID;
2267
+    $invoice_id = !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID;
2268 2268
     
2269 2269
     $subs_db    = new WPInv_Subscriptions_DB;
2270
-    $subs       = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) );
2270
+    $subs       = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1));
2271 2271
     
2272
-    if ( ! empty( $subs ) ) {
2273
-        return reset( $subs );
2272
+    if (!empty($subs)) {
2273
+        return reset($subs);
2274 2274
     }
2275 2275
     
2276 2276
     return false;
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.
includes/class-wpinv-api.php 2 patches
Doc Comments   +8 added lines patch added patch discarded remove patch
@@ -47,6 +47,9 @@  discard block
 block discarded – undo
47 47
         }
48 48
     }
49 49
     
50
+    /**
51
+     * @param integer $code
52
+     */
50 53
     public function send_status( $code ) {
51 54
         status_header( $code );
52 55
     }
@@ -195,6 +198,11 @@  discard block
 block discarded – undo
195 198
 class WPInv_API_Exception extends Exception {
196 199
     protected $error_code;
197 200
 
201
+    /**
202
+     * @param string $error_code
203
+     * @param string $error_message
204
+     * @param integer $http_status_code
205
+     */
198 206
     public function __construct( $error_code, $error_message, $http_status_code ) {
199 207
         $this->error_code = $error_code;
200 208
         parent::__construct( $error_message, $http_status_code );
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -7,51 +7,51 @@  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
 class WPInv_API {
15 15
     protected $post_type = 'wpi_invoice';
16 16
     
17
-    public function __construct( $params = array() ) {
17
+    public function __construct($params = array()) {
18 18
     }
19
-    public function insert_invoice( $data ) {
19
+    public function insert_invoice($data) {
20 20
         global $wpdb;
21 21
         //wpinv_transaction_query( 'start' );
22 22
 
23 23
         try {
24
-            if ( empty( $data['invoice'] ) ) {
25
-                throw new WPInv_API_Exception( 'wpinv_api_missing_invoice_data', sprintf( __( 'No %1$s data specified to create %1$s', 'invoicing' ), 'invoice' ), 400 );
24
+            if (empty($data['invoice'])) {
25
+                throw new WPInv_API_Exception('wpinv_api_missing_invoice_data', sprintf(__('No %1$s data specified to create %1$s', 'invoicing'), 'invoice'), 400);
26 26
             }
27 27
 
28
-            $data = apply_filters( 'wpinv_api_create_invoice_data', $data['invoice'], $this );
28
+            $data = apply_filters('wpinv_api_create_invoice_data', $data['invoice'], $this);
29 29
 
30
-            $invoice = wpinv_insert_invoice( $data, true );
31
-            if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) {
32
-                throw new WPInv_API_Exception( 'wpinv_api_cannot_create_invoice', sprintf( __( 'Cannot create invoice: %s', 'invoicing' ), implode( ', ', $invoice->get_error_messages() ) ), 400 );
30
+            $invoice = wpinv_insert_invoice($data, true);
31
+            if (empty($invoice->ID) || is_wp_error($invoice)) {
32
+                throw new WPInv_API_Exception('wpinv_api_cannot_create_invoice', sprintf(__('Cannot create invoice: %s', 'invoicing'), implode(', ', $invoice->get_error_messages())), 400);
33 33
             }
34 34
 
35 35
             // HTTP 201 Created
36
-            $this->send_status( 201 );
36
+            $this->send_status(201);
37 37
 
38
-            do_action( 'wpinv_api_create_invoice', $invoice->ID, $data, $this );
38
+            do_action('wpinv_api_create_invoice', $invoice->ID, $data, $this);
39 39
 
40 40
             //wpinv_transaction_query( 'commit' );
41 41
 
42
-            return wpinv_get_invoice( $invoice->ID );
43
-        } catch ( WPInv_API_Exception $e ) {
42
+            return wpinv_get_invoice($invoice->ID);
43
+        } catch (WPInv_API_Exception $e) {
44 44
             //wpinv_transaction_query( 'rollback' );
45 45
 
46
-            return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
46
+            return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
47 47
         }
48 48
     }
49 49
     
50
-    public function send_status( $code ) {
51
-        status_header( $code );
50
+    public function send_status($code) {
51
+        status_header($code);
52 52
     }
53 53
     
54
-    protected function set_billing_details( $invoice, $data ) {
54
+    protected function set_billing_details($invoice, $data) {
55 55
         $address_fields = array(
56 56
             'user_id',
57 57
             'first_name',
@@ -70,66 +70,66 @@  discard block
 block discarded – undo
70 70
         $billing_details = array();
71 71
         $user_id = $invoice->get_user_id();
72 72
         
73
-        foreach ( $address_fields as $field ) {
74
-            if ( isset( $data['billing_details'][ $field ] ) ) {
75
-                $value = sanitize_text_field( $data['billing_details'][ $field ] );
73
+        foreach ($address_fields as $field) {
74
+            if (isset($data['billing_details'][$field])) {
75
+                $value = sanitize_text_field($data['billing_details'][$field]);
76 76
                 
77
-                if ( $field == 'country' && empty( $value ) ) {
78
-                    if ( !empty( $invoice->country ) ) {
77
+                if ($field == 'country' && empty($value)) {
78
+                    if (!empty($invoice->country)) {
79 79
                         $value = $invoice->country;
80 80
                     } else {
81
-                        $value = wpinv_default_billing_country( '', $user_id );
81
+                        $value = wpinv_default_billing_country('', $user_id);
82 82
                     }
83 83
                 }
84 84
                 
85
-                if ( $field == 'state' && empty( $value ) ) {
86
-                    if ( !empty( $invoice->state ) ) {
85
+                if ($field == 'state' && empty($value)) {
86
+                    if (!empty($invoice->state)) {
87 87
                         $value = $invoice->state;
88 88
                     } else {
89 89
                         $value = wpinv_get_default_state();
90 90
                     }
91 91
                 }
92 92
                 
93
-                $invoice->set( $field, $value );
93
+                $invoice->set($field, $value);
94 94
                 
95
-                update_post_meta( $invoice->ID, '_wpinv_' . $field, $value );
95
+                update_post_meta($invoice->ID, '_wpinv_' . $field, $value);
96 96
             }
97 97
         }
98 98
         
99 99
         return $invoice;
100 100
     }
101 101
     
102
-    protected function set_discount( $invoice, $data ) {
103
-        if ( isset( $data['discount'] ) ) {
104
-            $invoice->set( 'discount', wpinv_round_amount( $data['discount'] ) );
102
+    protected function set_discount($invoice, $data) {
103
+        if (isset($data['discount'])) {
104
+            $invoice->set('discount', wpinv_round_amount($data['discount']));
105 105
             
106
-            update_post_meta( $invoice->ID, '_wpinv_discount', wpinv_round_amount( $data['discount'] ) );
106
+            update_post_meta($invoice->ID, '_wpinv_discount', wpinv_round_amount($data['discount']));
107 107
             
108
-            if ( isset( $data['discount_code'] ) ) {
109
-                $invoice->set( 'discount_code', $data['discount_code'] );
108
+            if (isset($data['discount_code'])) {
109
+                $invoice->set('discount_code', $data['discount_code']);
110 110
                 
111
-                update_post_meta( $invoice->ID, '_wpinv_discount_code', $data['discount_code'] );
111
+                update_post_meta($invoice->ID, '_wpinv_discount_code', $data['discount_code']);
112 112
             }
113 113
         }
114 114
         
115 115
         return $invoice;
116 116
     }
117 117
     
118
-    protected function set_items( $invoice, $data ) {
119
-        if ( !empty( $data['items'] ) && is_array( $data['items'] ) ) {
118
+    protected function set_items($invoice, $data) {
119
+        if (!empty($data['items']) && is_array($data['items'])) {
120 120
             $items_array = array();
121 121
            
122
-            if ( !empty( $invoice->country ) ) {
122
+            if (!empty($invoice->country)) {
123 123
                 $country = $invoice->country;
124
-            } else if ( !empty( $data['billing_details']['country'] ) ) {
124
+            } else if (!empty($data['billing_details']['country'])) {
125 125
                 $country = $data['billing_details']['country'];
126 126
             } else {
127
-                $country = wpinv_default_billing_country( '', $invoice->get_user_id() );
127
+                $country = wpinv_default_billing_country('', $invoice->get_user_id());
128 128
             }
129 129
             
130
-            if ( !empty( $invoice->state ) ) {
130
+            if (!empty($invoice->state)) {
131 131
                 $state = $invoice->state;
132
-            } else if ( !empty( $data['billing_details']['state'] ) ) {
132
+            } else if (!empty($data['billing_details']['state'])) {
133 133
                 $state = $data['billing_details']['state'];
134 134
             } else {
135 135
                 $state = wpinv_get_default_state();
@@ -138,54 +138,54 @@  discard block
 block discarded – undo
138 138
             $_POST['country']   = $country;
139 139
             $_POST['state']     = $state;
140 140
             
141
-            $rate = wpinv_get_tax_rate( $country, $state, 'global' );
141
+            $rate = wpinv_get_tax_rate($country, $state, 'global');
142 142
             
143 143
             $total_tax = 0;
144
-            foreach ( $data['items'] as $item ) {
145
-                $id                 = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
146
-                $title              = isset( $item['title'] ) ? sanitize_text_field( $item['title'] ) : '';
147
-                $desc               = isset( $item['description'] ) ? sanitize_text_field( $item['description'] ) : '';
148
-                $amount             = isset( $item['amount'] ) ? wpinv_round_amount( $item['amount'] ) : 0;
144
+            foreach ($data['items'] as $item) {
145
+                $id                 = isset($item['id']) ? sanitize_text_field($item['id']) : '';
146
+                $title              = isset($item['title']) ? sanitize_text_field($item['title']) : '';
147
+                $desc               = isset($item['description']) ? sanitize_text_field($item['description']) : '';
148
+                $amount             = isset($item['amount']) ? wpinv_round_amount($item['amount']) : 0;
149 149
                 
150
-                if ( !empty( $item['vat_rates_class'] ) ) {
150
+                if (!empty($item['vat_rates_class'])) {
151 151
                     $vat_rates_class = $item['vat_rates_class'];
152 152
                 } else {
153 153
                     $vat_rates_class = '_standard';
154 154
                 }
155
-                $vat_rate = wpinv_get_tax_rate( $country, $state, $id );
155
+                $vat_rate = wpinv_get_tax_rate($country, $state, $id);
156 156
                 
157
-                $tax = $amount > 0 ? ( $amount * 0.01 * (float)$vat_rate ) : 0;
157
+                $tax = $amount > 0 ? ($amount * 0.01 * (float)$vat_rate) : 0;
158 158
                 $total_tax += $tax;
159 159
                 
160 160
                 $items_array[] = array(
161 161
                     'id'                => $id,
162
-                    'title'             => esc_html( $title ),
163
-                    'description'       => esc_html( $desc ),
164
-                    'amount'            => $amount > 0 ? wpinv_round_amount( $amount ) : 0,
165
-                    'subtotal'          => $amount > 0 ? wpinv_round_amount( $amount ) : 0,
162
+                    'title'             => esc_html($title),
163
+                    'description'       => esc_html($desc),
164
+                    'amount'            => $amount > 0 ? wpinv_round_amount($amount) : 0,
165
+                    'subtotal'          => $amount > 0 ? wpinv_round_amount($amount) : 0,
166 166
                     'vat_rates_class'   => $vat_rates_class,
167 167
                     'vat_rate'          => $vat_rate,
168
-                    'tax'               => $tax > 0 ? wpinv_round_amount( $tax ) : 0,
168
+                    'tax'               => $tax > 0 ? wpinv_round_amount($tax) : 0,
169 169
                 );
170 170
             }
171 171
 
172
-            update_post_meta( $invoice->ID, '_wpinv_tax', wpinv_round_amount( $total_tax ) );
173
-            $invoice->set( 'tax', wpinv_round_amount( $total_tax ) );
172
+            update_post_meta($invoice->ID, '_wpinv_tax', wpinv_round_amount($total_tax));
173
+            $invoice->set('tax', wpinv_round_amount($total_tax));
174 174
             
175
-            $items_array = apply_filters( 'wpinv_save_invoice_items', $items_array, $data['items'], $invoice );
175
+            $items_array = apply_filters('wpinv_save_invoice_items', $items_array, $data['items'], $invoice);
176 176
             
177
-            $invoice->set( 'items', $items_array );
178
-            update_post_meta( $invoice->ID, '_wpinv_items', $items_array );
177
+            $invoice->set('items', $items_array);
178
+            update_post_meta($invoice->ID, '_wpinv_items', $items_array);
179 179
         }
180 180
         
181 181
         return $invoice;
182 182
     }
183 183
     
184
-    protected function set_invoice_meta( $invoice_id, $invoice_meta ) {
185
-        foreach ( $invoice_meta as $meta_key => $meta_value ) {
184
+    protected function set_invoice_meta($invoice_id, $invoice_meta) {
185
+        foreach ($invoice_meta as $meta_key => $meta_value) {
186 186
 
187
-            if ( is_string( $meta_key) && ! is_protected_meta( $meta_key ) && is_scalar( $meta_value ) ) {
188
-                update_post_meta( $invoice_id, $meta_key, $meta_value );
187
+            if (is_string($meta_key) && !is_protected_meta($meta_key) && is_scalar($meta_value)) {
188
+                update_post_meta($invoice_id, $meta_key, $meta_value);
189 189
             }
190 190
         }
191 191
     }
@@ -195,9 +195,9 @@  discard block
 block discarded – undo
195 195
 class WPInv_API_Exception extends Exception {
196 196
     protected $error_code;
197 197
 
198
-    public function __construct( $error_code, $error_message, $http_status_code ) {
198
+    public function __construct($error_code, $error_message, $http_status_code) {
199 199
         $this->error_code = $error_code;
200
-        parent::__construct( $error_message, $http_status_code );
200
+        parent::__construct($error_message, $http_status_code);
201 201
     }
202 202
 
203 203
     public function getErrorCode() {
Please login to merge, or discard this patch.