Passed
Pull Request — master (#126)
by Kiran
03:46
created
templates/wpinv-subscriptions-history.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -29,16 +29,16 @@
 block discarded – undo
29 29
     <table class="table table-bordered table-hover table-responsive wpi-user-subscriptions">
30 30
         <thead>
31 31
         <tr>
32
-            <th class="sub-no"><span class="nobr"><?php _e( 'No.', 'invoicing' ); ?></span></th>
33
-            <th class="sub-amount"><span class="nobr"><?php _e( 'Initial Amount', 'invoicing' ); ?></span></th>
34
-            <th class="sub-cycle"><span class="nobr"><?php _e( 'Billing Cycle', 'invoicing' ); ?></span></th>
35
-            <th class="sub-billed"><span class="nobr"><?php _e( 'Times Billed', 'invoicing' ); ?></span></th>
36
-            <th class="sub-status"><span class="nobr"><?php _e( 'Status', 'invoicing' ); ?></span></th>
37
-            <th class="sub-invoice"><span class="nobr"><?php _e( 'Invoice', 'invoicing' ); ?></span></th>
38
-            <th class="sub-item"><span class="nobr"><?php _e( 'Item', 'invoicing' ); ?></span></th>
39
-            <th class="sub-gateway"><span class="nobr"><?php _e( 'Gateway', 'invoicing' ); ?></span></th>
40
-            <th class="sub-expiry"><span class="nobr"><?php _e( 'Expires On', 'invoicing' ); ?></span></th>
41
-            <th class="sub-actions"><span class="nobr"><?php _e( 'Actions', 'invoicing' ); ?></span></th>
32
+            <th class="sub-no"><span class="nobr"><?php _e('No.', 'invoicing'); ?></span></th>
33
+            <th class="sub-amount"><span class="nobr"><?php _e('Initial Amount', 'invoicing'); ?></span></th>
34
+            <th class="sub-cycle"><span class="nobr"><?php _e('Billing Cycle', 'invoicing'); ?></span></th>
35
+            <th class="sub-billed"><span class="nobr"><?php _e('Times Billed', 'invoicing'); ?></span></th>
36
+            <th class="sub-status"><span class="nobr"><?php _e('Status', 'invoicing'); ?></span></th>
37
+            <th class="sub-invoice"><span class="nobr"><?php _e('Invoice', 'invoicing'); ?></span></th>
38
+            <th class="sub-item"><span class="nobr"><?php _e('Item', 'invoicing'); ?></span></th>
39
+            <th class="sub-gateway"><span class="nobr"><?php _e('Gateway', 'invoicing'); ?></span></th>
40
+            <th class="sub-expiry"><span class="nobr"><?php _e('Expires On', 'invoicing'); ?></span></th>
41
+            <th class="sub-actions"><span class="nobr"><?php _e('Actions', 'invoicing'); ?></span></th>
42 42
         </tr>
43 43
         </thead>
44 44
 
Please login to merge, or discard this patch.
templates/wpinv-invoice-history.php 1 patch
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -1,83 +1,83 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6
-if ( !( $user_id = get_current_user_id() ) ) {
6
+if (!($user_id = get_current_user_id())) {
7 7
     ?>
8
-    <div class="wpinv-empty alert alert-error"><?php _e( 'You are not allowed to access this section', 'invoicing' ) ;?></div>
8
+    <div class="wpinv-empty alert alert-error"><?php _e('You are not allowed to access this section', 'invoicing'); ?></div>
9 9
     <?php
10 10
     return;
11 11
 }
12 12
 
13 13
 global $current_page;
14
-$current_page   = empty( $current_page ) ? 1 : absint( $current_page );
15
-$query          = apply_filters( 'wpinv_user_invoices_query', array( 'user' => $user_id, 'page' => $current_page, 'paginate' => true ) );
16
-$user_invoices  = wpinv_get_invoices( $query );
14
+$current_page   = empty($current_page) ? 1 : absint($current_page);
15
+$query          = apply_filters('wpinv_user_invoices_query', array('user' => $user_id, 'page' => $current_page, 'paginate' => true));
16
+$user_invoices  = wpinv_get_invoices($query);
17 17
 $has_invoices   = 0 < $user_invoices->total;
18 18
     
19
-do_action( 'wpinv_before_user_invoices', $has_invoices ); ?>
19
+do_action('wpinv_before_user_invoices', $has_invoices); ?>
20 20
 
21
-<?php if ( $has_invoices ) { ?>
21
+<?php if ($has_invoices) { ?>
22 22
 	<table class="table table-bordered table-hover table-responsive wpi-user-invoices">
23 23
 		<thead>
24 24
 			<tr>
25
-				<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
26
-					<th class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>"><span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span></th>
25
+				<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
26
+					<th class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>"><span class="nobr"><?php echo esc_html($column_name['title']); ?></span></th>
27 27
 				<?php endforeach; ?>
28 28
 			</tr>
29 29
 		</thead>
30 30
 
31 31
 		<tbody>
32
-			<?php foreach ( $user_invoices->invoices as $invoice ) {
32
+			<?php foreach ($user_invoices->invoices as $invoice) {
33 33
 				?>
34 34
 				<tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>">
35
-					<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
36
-						<td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>">
37
-							<?php if ( has_action( 'wpinv_user_invoices_column_' . $column_id ) ) : ?>
38
-								<?php do_action( 'wpinv_user_invoices_column_' . $column_id, $invoice ); ?>
39
-
40
-							<?php elseif ( 'invoice-number' === $column_id ) : ?>
41
-								<a href="<?php echo esc_url( $invoice->get_view_url() ); ?>">
42
-									<?php echo _x( '#', 'hash before invoice number', 'invoicing' ) . $invoice->get_number(); ?>
35
+					<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
36
+						<td class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>" data-title="<?php echo esc_attr($column_name['title']); ?>">
37
+							<?php if (has_action('wpinv_user_invoices_column_' . $column_id)) : ?>
38
+								<?php do_action('wpinv_user_invoices_column_' . $column_id, $invoice); ?>
39
+
40
+							<?php elseif ('invoice-number' === $column_id) : ?>
41
+								<a href="<?php echo esc_url($invoice->get_view_url()); ?>">
42
+									<?php echo _x('#', 'hash before invoice number', 'invoicing') . $invoice->get_number(); ?>
43 43
 								</a>
44 44
 
45
-							<?php elseif ( 'created-date' === $column_id ) : $date = wpinv_get_date_created( $invoice->ID ); $dateYMD = wpinv_get_date_created( $invoice->ID, 'Y-m-d H:i:s' ); ?>
46
-								<time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
45
+							<?php elseif ('created-date' === $column_id) : $date = wpinv_get_date_created($invoice->ID); $dateYMD = wpinv_get_date_created($invoice->ID, 'Y-m-d H:i:s'); ?>
46
+								<time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
47 47
 
48
-							<?php elseif ( 'payment-date' === $column_id ) : $date = wpinv_get_invoice_date( $invoice->ID, '', false ); $dateYMD = wpinv_get_invoice_date( $invoice->ID, 'Y-m-d H:i:s', false ); ?>
49
-								<time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
48
+							<?php elseif ('payment-date' === $column_id) : $date = wpinv_get_invoice_date($invoice->ID, '', false); $dateYMD = wpinv_get_invoice_date($invoice->ID, 'Y-m-d H:i:s', false); ?>
49
+								<time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
50 50
 
51
-							<?php elseif ( 'invoice-status' === $column_id ) : ?>
52
-								<?php echo wpinv_invoice_status_label( $invoice_status, $invoice->get_status( true ) ) ; ?>
51
+							<?php elseif ('invoice-status' === $column_id) : ?>
52
+								<?php echo wpinv_invoice_status_label($invoice_status, $invoice->get_status(true)); ?>
53 53
 
54
-							<?php elseif ( 'invoice-total' === $column_id ) : ?>
55
-								<?php echo $invoice->get_total( true ); ?>
54
+							<?php elseif ('invoice-total' === $column_id) : ?>
55
+								<?php echo $invoice->get_total(true); ?>
56 56
 
57
-							<?php elseif ( 'invoice-actions' === $column_id ) : ?>
57
+							<?php elseif ('invoice-actions' === $column_id) : ?>
58 58
 								<?php
59 59
 									$actions = array(
60 60
 										'pay'    => array(
61 61
 											'url'  => $invoice->get_checkout_payment_url(),
62
-											'name' => __( 'Pay Now', 'invoicing' ),
62
+											'name' => __('Pay Now', 'invoicing'),
63 63
                                             'class' => 'btn-success'
64 64
 										),
65 65
                                         'print'   => array(
66 66
 											'url'  => $invoice->get_view_url(),
67
-											'name' => __( 'Print', 'invoicing' ),
67
+											'name' => __('Print', 'invoicing'),
68 68
                                             'class' => 'btn-primary',
69 69
                                             'attrs' => 'target="_blank"'
70 70
 										)
71 71
 									);
72 72
 
73
-									if ( ! $invoice->needs_payment() ) {
74
-										unset( $actions['pay'] );
73
+									if (!$invoice->needs_payment()) {
74
+										unset($actions['pay']);
75 75
 									}
76 76
 
77
-									if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) {
78
-										foreach ( $actions as $key => $action ) {
77
+									if ($actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice)) {
78
+										foreach ($actions as $key => $action) {
79 79
 											$class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
80
-                                            echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
80
+                                            echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>';
81 81
 										}
82 82
 									}
83 83
 								?>
@@ -89,9 +89,9 @@  discard block
 block discarded – undo
89 89
 		</tbody>
90 90
 	</table>
91 91
 
92
-	<?php do_action( 'wpinv_before_user_invoices_pagination' ); ?>
92
+	<?php do_action('wpinv_before_user_invoices_pagination'); ?>
93 93
 
94
-	<?php if ( 1 < $user_invoices->max_num_pages ) : ?>
94
+	<?php if (1 < $user_invoices->max_num_pages) : ?>
95 95
 		<div class="invoicing-Pagination">
96 96
 			<?php
97 97
 			$big = 999999;
@@ -103,20 +103,20 @@  discard block
 block discarded – undo
103 103
 			else
104 104
 				$current_page = 1;
105 105
 
106
-			echo paginate_links( array(
107
-				'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
106
+			echo paginate_links(array(
107
+				'base'    => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
108 108
 				'format'  => '?paged=%#%',
109
-				'current' => max( 1, $current_page ),
109
+				'current' => max(1, $current_page),
110 110
 				'total'   => $user_invoices->max_num_pages,
111
-			) );
111
+			));
112 112
 			?>
113 113
 		</div>
114 114
 	<?php endif; ?>
115 115
 
116 116
 <?php } else { ?>
117 117
 	<div class="wpinv-empty alert-info">
118
-		<?php _e( 'No invoice has been made yet.', 'invoicing' ); ?>
118
+		<?php _e('No invoice has been made yet.', 'invoicing'); ?>
119 119
 	</div>
120 120
 <?php } ?>
121 121
 
122
-<?php do_action( 'wpinv_after_user_invoices', $has_invoices ); ?>
122
+<?php do_action('wpinv_after_user_invoices', $has_invoices); ?>
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 1 patch
Spacing   +376 added lines, -376 removed lines patch added patch discarded remove patch
@@ -7,128 +7,128 @@  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_item_quantities_enabled() {
15
-    $ret = wpinv_get_option( 'item_quantities', true );
15
+    $ret = wpinv_get_option('item_quantities', true);
16 16
 
17
-    return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret );
17
+    return (bool)apply_filters('wpinv_item_quantities_enabled', $ret);
18 18
 }
19 19
 
20 20
 function wpinv_get_ip() {
21 21
     $ip = '127.0.0.1';
22 22
 
23
-    if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
-        $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
25
-    } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
26
-        $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
27
-    } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
28
-        $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
23
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24
+        $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
25
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
+        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
27
+    } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
28
+        $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
29 29
     }
30 30
 
31
-    return apply_filters( 'wpinv_get_ip', $ip );
31
+    return apply_filters('wpinv_get_ip', $ip);
32 32
 }
33 33
 
34 34
 function wpinv_get_user_agent() {
35
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
35
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
36
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
37 37
     } else {
38 38
         $user_agent = '';
39 39
     }
40 40
 
41
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
41
+    return apply_filters('wpinv_get_user_agent', $user_agent);
42 42
 }
43 43
 
44
-function wpinv_sanitize_amount( $amount, $decimals = NULL ) {
44
+function wpinv_sanitize_amount($amount, $decimals = NULL) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_separator();
47 47
     $decimal_sep   = wpinv_decimal_separator();
48
-    if ( $decimals === NULL ) {
48
+    if ($decimals === NULL) {
49 49
         $decimals = wpinv_decimals();
50 50
     }
51 51
 
52 52
     // Sanitize the amount
53
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
54
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
55
-            $amount = str_replace( $thousands_sep, '', $amount );
56
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
57
-            $amount = str_replace( '.', '', $amount );
53
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
54
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
55
+            $amount = str_replace($thousands_sep, '', $amount);
56
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
57
+            $amount = str_replace('.', '', $amount);
58 58
         }
59 59
 
60
-        $amount = str_replace( $decimal_sep, '.', $amount );
61
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
62
-        $amount = str_replace( $thousands_sep, '', $amount );
60
+        $amount = str_replace($decimal_sep, '.', $amount);
61
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
62
+        $amount = str_replace($thousands_sep, '', $amount);
63 63
     }
64 64
 
65
-    if( $amount < 0 ) {
65
+    if ($amount < 0) {
66 66
         $is_negative = true;
67 67
     }
68 68
 
69
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
69
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
70 70
 
71
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount );
72
-    $amount   = number_format( (double) $amount, absint( $decimals ), '.', '' );
71
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount);
72
+    $amount   = number_format((double)$amount, absint($decimals), '.', '');
73 73
 
74
-    if( $is_negative ) {
74
+    if ($is_negative) {
75 75
         $amount *= -1;
76 76
     }
77 77
 
78
-    return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals );
78
+    return apply_filters('wpinv_sanitize_amount', $amount, $decimals);
79 79
 }
80
-add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
80
+add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1);
81 81
 
82
-function wpinv_round_amount( $amount, $decimals = NULL ) {
83
-    if ( $decimals === NULL ) {
82
+function wpinv_round_amount($amount, $decimals = NULL) {
83
+    if ($decimals === NULL) {
84 84
         $decimals = wpinv_decimals();
85 85
     }
86 86
     
87
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
87
+    $amount = round((double)$amount, wpinv_currency_decimal_filter(absint($decimals)));
88 88
 
89
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
89
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
90 90
 }
91 91
 
92
-function wpinv_get_invoice_statuses( $trashed = false, $invoice = false ) {
92
+function wpinv_get_invoice_statuses($trashed = false, $invoice = false) {
93 93
     global $post;
94 94
 
95 95
     $invoice_statuses = array(
96
-        'wpi-pending' => __( 'Pending Payment', 'invoicing' ),
97
-        'publish' => __( 'Paid', 'invoicing'),
98
-        'wpi-processing' => __( 'Processing', 'invoicing' ),
99
-        'wpi-onhold' => __( 'On Hold', 'invoicing' ),
100
-        'wpi-refunded' => __( 'Refunded', 'invoicing' ),
101
-        'wpi-cancelled' => __( 'Cancelled', 'invoicing' ),
102
-        'wpi-failed' => __( 'Failed', 'invoicing' ),
103
-        'wpi-renewal' => __( 'Renewal Payment', 'invoicing' )
96
+        'wpi-pending' => __('Pending Payment', 'invoicing'),
97
+        'publish' => __('Paid', 'invoicing'),
98
+        'wpi-processing' => __('Processing', 'invoicing'),
99
+        'wpi-onhold' => __('On Hold', 'invoicing'),
100
+        'wpi-refunded' => __('Refunded', 'invoicing'),
101
+        'wpi-cancelled' => __('Cancelled', 'invoicing'),
102
+        'wpi-failed' => __('Failed', 'invoicing'),
103
+        'wpi-renewal' => __('Renewal Payment', 'invoicing')
104 104
     );
105 105
 
106
-    if ( $trashed ) {
107
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
106
+    if ($trashed) {
107
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
108 108
     }
109 109
 
110
-    return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
110
+    return apply_filters('wpinv_statuses', $invoice_statuses, $invoice);
111 111
 }
112 112
 
113
-function wpinv_status_nicename( $status ) {
113
+function wpinv_status_nicename($status) {
114 114
     $statuses = wpinv_get_invoice_statuses();
115
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
115
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
116 116
 
117 117
     return $status;
118 118
 }
119 119
 
120 120
 function wpinv_get_currency() {
121
-    $currency = wpinv_get_option( 'currency', 'USD' );
121
+    $currency = wpinv_get_option('currency', 'USD');
122 122
     
123
-    return apply_filters( 'wpinv_currency', $currency );
123
+    return apply_filters('wpinv_currency', $currency);
124 124
 }
125 125
 
126
-function wpinv_currency_symbol( $currency = '' ) {
127
-    if ( empty( $currency ) ) {
126
+function wpinv_currency_symbol($currency = '') {
127
+    if (empty($currency)) {
128 128
         $currency = wpinv_get_currency();
129 129
     }
130 130
     
131
-    $symbols = apply_filters( 'wpinv_currency_symbols', array(
131
+    $symbols = apply_filters('wpinv_currency_symbols', array(
132 132
         'AED' => '&#x62f;.&#x625;',
133 133
         'AFN' => '&#x60b;',
134 134
         'ALL' => 'L',
@@ -291,208 +291,208 @@  discard block
 block discarded – undo
291 291
         'YER' => '&#xfdfc;',
292 292
         'ZAR' => '&#82;',
293 293
         'ZMW' => 'ZK',
294
-    ) );
294
+    ));
295 295
 
296
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency;
296
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency;
297 297
 
298
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
298
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
299 299
 }
300 300
 
301 301
 function wpinv_currency_position() {
302
-    $position = wpinv_get_option( 'currency_position', 'left' );
302
+    $position = wpinv_get_option('currency_position', 'left');
303 303
     
304
-    return apply_filters( 'wpinv_currency_position', $position );
304
+    return apply_filters('wpinv_currency_position', $position);
305 305
 }
306 306
 
307 307
 function wpinv_thousands_separator() {
308
-    $thousand_sep = wpinv_get_option( 'thousands_separator', ',' );
308
+    $thousand_sep = wpinv_get_option('thousands_separator', ',');
309 309
     
310
-    return apply_filters( 'wpinv_thousands_separator', $thousand_sep );
310
+    return apply_filters('wpinv_thousands_separator', $thousand_sep);
311 311
 }
312 312
 
313 313
 function wpinv_decimal_separator() {
314
-    $decimal_sep = wpinv_get_option( 'decimal_separator', '.' );
314
+    $decimal_sep = wpinv_get_option('decimal_separator', '.');
315 315
     
316
-    return apply_filters( 'wpinv_decimal_separator', $decimal_sep );
316
+    return apply_filters('wpinv_decimal_separator', $decimal_sep);
317 317
 }
318 318
 
319 319
 function wpinv_decimals() {
320
-    $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) );
320
+    $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2));
321 321
     
322
-    return absint( $decimals );
322
+    return absint($decimals);
323 323
 }
324 324
 
325 325
 function wpinv_get_currencies() {
326 326
     $currencies = array(
327
-        'USD' => __( 'US Dollar', 'invoicing' ),
328
-        'EUR' => __( 'Euro', 'invoicing' ),
329
-        'GBP' => __( 'Pound Sterling', 'invoicing' ),
330
-        'AFN' => __( 'Afghan Afghani', 'invoicing' ),
331
-        'ALL' => __( 'Albanian Lek', 'invoicing' ),
332
-        'AMD' => __( 'Armenian Dram', 'invoicing' ),
333
-        'ANG' => __( 'Netherlands Antillean Guilder', 'invoicing' ),
334
-        'AOA' => __( 'Angolan Kwanza', 'invoicing' ),
335
-        'ARS' => __( 'Argentine Peso', 'invoicing' ),
336
-        'AUD' => __( 'Australian Dollar', 'invoicing' ),
337
-        'AWG' => __( 'Aruban Florin', 'invoicing' ),
338
-        'AZN' => __( 'Azerbaijani Manat', 'invoicing' ),
339
-        'BAM' => __( 'Bosnia and Herzegovina Convertible Marka', 'invoicing' ),
340
-        'BBD' => __( 'Barbadian Dollar', 'invoicing' ),
341
-        'BDT' => __( 'Bangladeshi Taka', 'invoicing' ),
342
-        'BGN' => __( 'Bulgarian Lev', 'invoicing' ),
343
-        'BHD' => __( 'Bahraini Dinar', 'invoicing' ),
344
-        'BIF' => __( 'Burundian Franc', 'invoicing' ),
345
-        'BMD' => __( 'Bermudian Dollar', 'invoicing' ),
346
-        'BND' => __( 'Brunei Dollar', 'invoicing' ),
347
-        'BOB' => __( 'Bolivian Boliviano', 'invoicing' ),
348
-        'BRL' => __( 'Brazilian Real', 'invoicing' ),
349
-        'BSD' => __( 'Bahamian Dollar', 'invoicing' ),
350
-        'BTC' => __( 'Bitcoin', 'invoicing' ),
351
-        'BTN' => __( 'Bhutanese Ngultrum', 'invoicing' ),
352
-        'BWP' => __( 'Botswana Pula', 'invoicing' ),
353
-        'BYN' => __( 'Belarusian Ruble', 'invoicing' ),
354
-        'BZD' => __( 'Belize Dollar', 'invoicing' ),
355
-        'CAD' => __( 'Canadian Dollar', 'invoicing' ),
356
-        'CDF' => __( 'Congolese Franc', 'invoicing' ),
357
-        'CHF' => __( 'Swiss Franc', 'invoicing' ),
358
-        'CLP' => __( 'Chilean Peso', 'invoicing' ),
359
-        'CNY' => __( 'Chinese Yuan', 'invoicing' ),
360
-        'COP' => __( 'Colombian Peso', 'invoicing' ),
361
-        'CRC' => __( 'Costa Rican Colon', 'invoicing' ),
362
-        'CUC' => __( 'Cuban Convertible Peso', 'invoicing' ),
363
-        'CUP' => __( 'Cuban Peso', 'invoicing' ),
364
-        'CVE' => __( 'Cape Verdean escudo', 'invoicing' ),
365
-        'CZK' => __( 'Czech Koruna', 'invoicing' ),
366
-        'DJF' => __( 'Djiboutian Franc', 'invoicing' ),
367
-        'DKK' => __( 'Danish Krone', 'invoicing' ),
368
-        'DOP' => __( 'Dominican Peso', 'invoicing' ),
369
-        'DZD' => __( 'Algerian Dinar', 'invoicing' ),
370
-        'EGP' => __( 'Egyptian Pound', 'invoicing' ),
371
-        'ERN' => __( 'Eritrean Nakfa', 'invoicing' ),
372
-        'ETB' => __( 'Ethiopian irr', 'invoicing' ),
373
-        'FJD' => __( 'Fijian Dollar', 'invoicing' ),
374
-        'FKP' => __( 'Falkland Islands Pound', 'invoicing' ),
375
-        'GEL' => __( 'Georgian lari', 'invoicing' ),
376
-        'GGP' => __( 'Guernsey Pound', 'invoicing' ),
377
-        'GHS' => __( 'Ghana cedi', 'invoicing' ),
378
-        'GIP' => __( 'Gibraltar Pound', 'invoicing' ),
379
-        'GMD' => __( 'Gambian Dalasi', 'invoicing' ),
380
-        'GNF' => __( 'Guinean Franc', 'invoicing' ),
381
-        'GTQ' => __( 'Guatemalan Quetzal', 'invoicing' ),
382
-        'GYD' => __( 'Guyanese Dollar', 'invoicing' ),
383
-        'HKD' => __( 'Hong Kong Dollar', 'invoicing' ),
384
-        'HNL' => __( 'Honduran Lempira', 'invoicing' ),
385
-        'HRK' => __( 'Croatian Kuna', 'invoicing' ),
386
-        'HTG' => __( 'Haitian Gourde', 'invoicing' ),
387
-        'HUF' => __( 'Hungarian Forint', 'invoicing' ),
388
-        'IDR' => __( 'Indonesian Rupiah', 'invoicing' ),
389
-        'ILS' => __( 'Israeli New Shekel', 'invoicing' ),
390
-        'IMP' => __( 'Manx Pound', 'invoicing' ),
391
-        'INR' => __( 'Indian Rupee', 'invoicing' ),
392
-        'IQD' => __( 'Iraqi Dinar', 'invoicing' ),
393
-        'IRR' => __( 'Iranian Rial', 'invoicing' ),
394
-        'IRT' => __( 'Iranian Toman', 'invoicing' ),
395
-        'ISK' => __( 'Icelandic Krona', 'invoicing' ),
396
-        'JEP' => __( 'Jersey Pound', 'invoicing' ),
397
-        'JMD' => __( 'Jamaican Dollar', 'invoicing' ),
398
-        'JOD' => __( 'Jordanian Dinar', 'invoicing' ),
399
-        'JPY' => __( 'Japanese Yen', 'invoicing' ),
400
-        'KES' => __( 'Kenyan Shilling', 'invoicing' ),
401
-        'KGS' => __( 'Kyrgyzstani Som', 'invoicing' ),
402
-        'KHR' => __( 'Cambodian Riel', 'invoicing' ),
403
-        'KMF' => __( 'Comorian Franc', 'invoicing' ),
404
-        'KPW' => __( 'North Korean Won', 'invoicing' ),
405
-        'KRW' => __( 'South Korean Won', 'invoicing' ),
406
-        'KWD' => __( 'Kuwaiti Dinar', 'invoicing' ),
407
-        'KYD' => __( 'Cayman Islands Dollar', 'invoicing' ),
408
-        'KZT' => __( 'Kazakhstani Tenge', 'invoicing' ),
409
-        'LAK' => __( 'Lao Kip', 'invoicing' ),
410
-        'LBP' => __( 'Lebanese Pound', 'invoicing' ),
411
-        'LKR' => __( 'Sri Lankan Rupee', 'invoicing' ),
412
-        'LRD' => __( 'Liberian Dollar', 'invoicing' ),
413
-        'LSL' => __( 'Lesotho Loti', 'invoicing' ),
414
-        'LYD' => __( 'Libyan Dinar', 'invoicing' ),
415
-        'MAD' => __( 'Moroccan Dirham', 'invoicing' ),
416
-        'MDL' => __( 'Moldovan Leu', 'invoicing' ),
417
-        'MGA' => __( 'Malagasy Ariary', 'invoicing' ),
418
-        'MKD' => __( 'Macedonian Denar', 'invoicing' ),
419
-        'MMK' => __( 'Burmese Kyat', 'invoicing' ),
420
-        'MNT' => __( 'Mongolian Tughrik', 'invoicing' ),
421
-        'MOP' => __( 'Macanese Pataca', 'invoicing' ),
422
-        'MRO' => __( 'Mauritanian Ouguiya', 'invoicing' ),
423
-        'MUR' => __( 'Mauritian Rupee', 'invoicing' ),
424
-        'MVR' => __( 'Maldivian Rufiyaa', 'invoicing' ),
425
-        'MWK' => __( 'Malawian Kwacha', 'invoicing' ),
426
-        'MXN' => __( 'Mexican Peso', 'invoicing' ),
427
-        'MYR' => __( 'Malaysian Ringgit', 'invoicing' ),
428
-        'MZN' => __( 'Mozambican Metical', 'invoicing' ),
429
-        'NAD' => __( 'Namibian Dollar', 'invoicing' ),
430
-        'NGN' => __( 'Nigerian Naira', 'invoicing' ),
431
-        'NIO' => __( 'Nicaraguan Cordoba', 'invoicing' ),
432
-        'NOK' => __( 'Norwegian Krone', 'invoicing' ),
433
-        'NPR' => __( 'Nepalese Rupee', 'invoicing' ),
434
-        'NZD' => __( 'New Zealand Dollar', 'invoicing' ),
435
-        'OMR' => __( 'Omani Rial', 'invoicing' ),
436
-        'PAB' => __( 'Panamanian Balboa', 'invoicing' ),
437
-        'PEN' => __( 'Peruvian Nuevo Sol', 'invoicing' ),
438
-        'PGK' => __( 'Papua New Guinean Kina', 'invoicing' ),
439
-        'PHP' => __( 'Philippine Peso', 'invoicing' ),
440
-        'PKR' => __( 'Pakistani Rupee', 'invoicing' ),
441
-        'PLN' => __( 'Polish Zloty', 'invoicing' ),
442
-        'PRB' => __( 'Transnistrian Ruble', 'invoicing' ),
443
-        'PYG' => __( 'Paraguayan Guarani', 'invoicing' ),
444
-        'QAR' => __( 'Qatari Riyal', 'invoicing' ),
445
-        'RON' => __( 'Romanian Leu', 'invoicing' ),
446
-        'RSD' => __( 'Serbian Dinar', 'invoicing' ),
447
-        'RUB' => __( 'Russian Ruble', 'invoicing' ),
448
-        'RWF' => __( 'Rwandan Franc', 'invoicing' ),
449
-        'SAR' => __( 'Saudi Riyal', 'invoicing' ),
450
-        'SBD' => __( 'Solomon Islands Dollar', 'invoicing' ),
451
-        'SCR' => __( 'Seychellois Rupee', 'invoicing' ),
452
-        'SDG' => __( 'Sudanese Pound', 'invoicing' ),
453
-        'SEK' => __( 'Swedish Krona', 'invoicing' ),
454
-        'SGD' => __( 'Singapore Dollar', 'invoicing' ),
455
-        'SHP' => __( 'Saint Helena Pound', 'invoicing' ),
456
-        'SLL' => __( 'Sierra Leonean Leone', 'invoicing' ),
457
-        'SOS' => __( 'Somali Shilling', 'invoicing' ),
458
-        'SRD' => __( 'Surinamese Dollar', 'invoicing' ),
459
-        'SSP' => __( 'South Sudanese Pound', 'invoicing' ),
460
-        'STD' => __( 'Sao Tomean Dobra', 'invoicing' ),
461
-        'SYP' => __( 'Syrian Pound', 'invoicing' ),
462
-        'SZL' => __( 'Swazi Lilangeni', 'invoicing' ),
463
-        'THB' => __( 'Thai Baht', 'invoicing' ),
464
-        'TJS' => __( 'Tajikistani Somoni', 'invoicing' ),
465
-        'TMT' => __( 'Turkmenistan Manat', 'invoicing' ),
466
-        'TND' => __( 'Tunisian Dinar', 'invoicing' ),
467
-        'TOP' => __( 'Tongan Pa&#x2bb;anga', 'invoicing' ),
468
-        'TRY' => __( 'Turkish Lira', 'invoicing' ),
469
-        'TTD' => __( 'Trinidad and Tobago Dollar', 'invoicing' ),
470
-        'TWD' => __( 'New Taiwan Dollar', 'invoicing' ),
471
-        'TZS' => __( 'Tanzanian Shilling', 'invoicing' ),
472
-        'UAH' => __( 'Ukrainian Hryvnia', 'invoicing' ),
473
-        'UGX' => __( 'Ugandan Shilling', 'invoicing' ),
474
-        'UYU' => __( 'Uruguayan Peso', 'invoicing' ),
475
-        'UZS' => __( 'Uzbekistani Som', 'invoicing' ),
476
-        'VEF' => __( 'Venezuelan Bol&iacute;var', 'invoicing' ),
477
-        'VND' => __( 'Vietnamese Dong', 'invoicing' ),
478
-        'VUV' => __( 'Vanuatu Vatu', 'invoicing' ),
479
-        'WST' => __( 'Samoan Tala', 'invoicing' ),
480
-        'XAF' => __( 'Central African CFA Franc', 'invoicing' ),
481
-        'XCD' => __( 'East Caribbean Dollar', 'invoicing' ),
482
-        'XOF' => __( 'West African CFA Franc', 'invoicing' ),
483
-        'XPF' => __( 'CFP Franc', 'invoicing' ),
484
-        'YER' => __( 'Yemeni Rial', 'invoicing' ),
485
-        'ZAR' => __( 'South African Rand', 'invoicing' ),
486
-        'ZMW' => __( 'Zambian Kwacha', 'invoicing' ),
327
+        'USD' => __('US Dollar', 'invoicing'),
328
+        'EUR' => __('Euro', 'invoicing'),
329
+        'GBP' => __('Pound Sterling', 'invoicing'),
330
+        'AFN' => __('Afghan Afghani', 'invoicing'),
331
+        'ALL' => __('Albanian Lek', 'invoicing'),
332
+        'AMD' => __('Armenian Dram', 'invoicing'),
333
+        'ANG' => __('Netherlands Antillean Guilder', 'invoicing'),
334
+        'AOA' => __('Angolan Kwanza', 'invoicing'),
335
+        'ARS' => __('Argentine Peso', 'invoicing'),
336
+        'AUD' => __('Australian Dollar', 'invoicing'),
337
+        'AWG' => __('Aruban Florin', 'invoicing'),
338
+        'AZN' => __('Azerbaijani Manat', 'invoicing'),
339
+        'BAM' => __('Bosnia and Herzegovina Convertible Marka', 'invoicing'),
340
+        'BBD' => __('Barbadian Dollar', 'invoicing'),
341
+        'BDT' => __('Bangladeshi Taka', 'invoicing'),
342
+        'BGN' => __('Bulgarian Lev', 'invoicing'),
343
+        'BHD' => __('Bahraini Dinar', 'invoicing'),
344
+        'BIF' => __('Burundian Franc', 'invoicing'),
345
+        'BMD' => __('Bermudian Dollar', 'invoicing'),
346
+        'BND' => __('Brunei Dollar', 'invoicing'),
347
+        'BOB' => __('Bolivian Boliviano', 'invoicing'),
348
+        'BRL' => __('Brazilian Real', 'invoicing'),
349
+        'BSD' => __('Bahamian Dollar', 'invoicing'),
350
+        'BTC' => __('Bitcoin', 'invoicing'),
351
+        'BTN' => __('Bhutanese Ngultrum', 'invoicing'),
352
+        'BWP' => __('Botswana Pula', 'invoicing'),
353
+        'BYN' => __('Belarusian Ruble', 'invoicing'),
354
+        'BZD' => __('Belize Dollar', 'invoicing'),
355
+        'CAD' => __('Canadian Dollar', 'invoicing'),
356
+        'CDF' => __('Congolese Franc', 'invoicing'),
357
+        'CHF' => __('Swiss Franc', 'invoicing'),
358
+        'CLP' => __('Chilean Peso', 'invoicing'),
359
+        'CNY' => __('Chinese Yuan', 'invoicing'),
360
+        'COP' => __('Colombian Peso', 'invoicing'),
361
+        'CRC' => __('Costa Rican Colon', 'invoicing'),
362
+        'CUC' => __('Cuban Convertible Peso', 'invoicing'),
363
+        'CUP' => __('Cuban Peso', 'invoicing'),
364
+        'CVE' => __('Cape Verdean escudo', 'invoicing'),
365
+        'CZK' => __('Czech Koruna', 'invoicing'),
366
+        'DJF' => __('Djiboutian Franc', 'invoicing'),
367
+        'DKK' => __('Danish Krone', 'invoicing'),
368
+        'DOP' => __('Dominican Peso', 'invoicing'),
369
+        'DZD' => __('Algerian Dinar', 'invoicing'),
370
+        'EGP' => __('Egyptian Pound', 'invoicing'),
371
+        'ERN' => __('Eritrean Nakfa', 'invoicing'),
372
+        'ETB' => __('Ethiopian irr', 'invoicing'),
373
+        'FJD' => __('Fijian Dollar', 'invoicing'),
374
+        'FKP' => __('Falkland Islands Pound', 'invoicing'),
375
+        'GEL' => __('Georgian lari', 'invoicing'),
376
+        'GGP' => __('Guernsey Pound', 'invoicing'),
377
+        'GHS' => __('Ghana cedi', 'invoicing'),
378
+        'GIP' => __('Gibraltar Pound', 'invoicing'),
379
+        'GMD' => __('Gambian Dalasi', 'invoicing'),
380
+        'GNF' => __('Guinean Franc', 'invoicing'),
381
+        'GTQ' => __('Guatemalan Quetzal', 'invoicing'),
382
+        'GYD' => __('Guyanese Dollar', 'invoicing'),
383
+        'HKD' => __('Hong Kong Dollar', 'invoicing'),
384
+        'HNL' => __('Honduran Lempira', 'invoicing'),
385
+        'HRK' => __('Croatian Kuna', 'invoicing'),
386
+        'HTG' => __('Haitian Gourde', 'invoicing'),
387
+        'HUF' => __('Hungarian Forint', 'invoicing'),
388
+        'IDR' => __('Indonesian Rupiah', 'invoicing'),
389
+        'ILS' => __('Israeli New Shekel', 'invoicing'),
390
+        'IMP' => __('Manx Pound', 'invoicing'),
391
+        'INR' => __('Indian Rupee', 'invoicing'),
392
+        'IQD' => __('Iraqi Dinar', 'invoicing'),
393
+        'IRR' => __('Iranian Rial', 'invoicing'),
394
+        'IRT' => __('Iranian Toman', 'invoicing'),
395
+        'ISK' => __('Icelandic Krona', 'invoicing'),
396
+        'JEP' => __('Jersey Pound', 'invoicing'),
397
+        'JMD' => __('Jamaican Dollar', 'invoicing'),
398
+        'JOD' => __('Jordanian Dinar', 'invoicing'),
399
+        'JPY' => __('Japanese Yen', 'invoicing'),
400
+        'KES' => __('Kenyan Shilling', 'invoicing'),
401
+        'KGS' => __('Kyrgyzstani Som', 'invoicing'),
402
+        'KHR' => __('Cambodian Riel', 'invoicing'),
403
+        'KMF' => __('Comorian Franc', 'invoicing'),
404
+        'KPW' => __('North Korean Won', 'invoicing'),
405
+        'KRW' => __('South Korean Won', 'invoicing'),
406
+        'KWD' => __('Kuwaiti Dinar', 'invoicing'),
407
+        'KYD' => __('Cayman Islands Dollar', 'invoicing'),
408
+        'KZT' => __('Kazakhstani Tenge', 'invoicing'),
409
+        'LAK' => __('Lao Kip', 'invoicing'),
410
+        'LBP' => __('Lebanese Pound', 'invoicing'),
411
+        'LKR' => __('Sri Lankan Rupee', 'invoicing'),
412
+        'LRD' => __('Liberian Dollar', 'invoicing'),
413
+        'LSL' => __('Lesotho Loti', 'invoicing'),
414
+        'LYD' => __('Libyan Dinar', 'invoicing'),
415
+        'MAD' => __('Moroccan Dirham', 'invoicing'),
416
+        'MDL' => __('Moldovan Leu', 'invoicing'),
417
+        'MGA' => __('Malagasy Ariary', 'invoicing'),
418
+        'MKD' => __('Macedonian Denar', 'invoicing'),
419
+        'MMK' => __('Burmese Kyat', 'invoicing'),
420
+        'MNT' => __('Mongolian Tughrik', 'invoicing'),
421
+        'MOP' => __('Macanese Pataca', 'invoicing'),
422
+        'MRO' => __('Mauritanian Ouguiya', 'invoicing'),
423
+        'MUR' => __('Mauritian Rupee', 'invoicing'),
424
+        'MVR' => __('Maldivian Rufiyaa', 'invoicing'),
425
+        'MWK' => __('Malawian Kwacha', 'invoicing'),
426
+        'MXN' => __('Mexican Peso', 'invoicing'),
427
+        'MYR' => __('Malaysian Ringgit', 'invoicing'),
428
+        'MZN' => __('Mozambican Metical', 'invoicing'),
429
+        'NAD' => __('Namibian Dollar', 'invoicing'),
430
+        'NGN' => __('Nigerian Naira', 'invoicing'),
431
+        'NIO' => __('Nicaraguan Cordoba', 'invoicing'),
432
+        'NOK' => __('Norwegian Krone', 'invoicing'),
433
+        'NPR' => __('Nepalese Rupee', 'invoicing'),
434
+        'NZD' => __('New Zealand Dollar', 'invoicing'),
435
+        'OMR' => __('Omani Rial', 'invoicing'),
436
+        'PAB' => __('Panamanian Balboa', 'invoicing'),
437
+        'PEN' => __('Peruvian Nuevo Sol', 'invoicing'),
438
+        'PGK' => __('Papua New Guinean Kina', 'invoicing'),
439
+        'PHP' => __('Philippine Peso', 'invoicing'),
440
+        'PKR' => __('Pakistani Rupee', 'invoicing'),
441
+        'PLN' => __('Polish Zloty', 'invoicing'),
442
+        'PRB' => __('Transnistrian Ruble', 'invoicing'),
443
+        'PYG' => __('Paraguayan Guarani', 'invoicing'),
444
+        'QAR' => __('Qatari Riyal', 'invoicing'),
445
+        'RON' => __('Romanian Leu', 'invoicing'),
446
+        'RSD' => __('Serbian Dinar', 'invoicing'),
447
+        'RUB' => __('Russian Ruble', 'invoicing'),
448
+        'RWF' => __('Rwandan Franc', 'invoicing'),
449
+        'SAR' => __('Saudi Riyal', 'invoicing'),
450
+        'SBD' => __('Solomon Islands Dollar', 'invoicing'),
451
+        'SCR' => __('Seychellois Rupee', 'invoicing'),
452
+        'SDG' => __('Sudanese Pound', 'invoicing'),
453
+        'SEK' => __('Swedish Krona', 'invoicing'),
454
+        'SGD' => __('Singapore Dollar', 'invoicing'),
455
+        'SHP' => __('Saint Helena Pound', 'invoicing'),
456
+        'SLL' => __('Sierra Leonean Leone', 'invoicing'),
457
+        'SOS' => __('Somali Shilling', 'invoicing'),
458
+        'SRD' => __('Surinamese Dollar', 'invoicing'),
459
+        'SSP' => __('South Sudanese Pound', 'invoicing'),
460
+        'STD' => __('Sao Tomean Dobra', 'invoicing'),
461
+        'SYP' => __('Syrian Pound', 'invoicing'),
462
+        'SZL' => __('Swazi Lilangeni', 'invoicing'),
463
+        'THB' => __('Thai Baht', 'invoicing'),
464
+        'TJS' => __('Tajikistani Somoni', 'invoicing'),
465
+        'TMT' => __('Turkmenistan Manat', 'invoicing'),
466
+        'TND' => __('Tunisian Dinar', 'invoicing'),
467
+        'TOP' => __('Tongan Pa&#x2bb;anga', 'invoicing'),
468
+        'TRY' => __('Turkish Lira', 'invoicing'),
469
+        'TTD' => __('Trinidad and Tobago Dollar', 'invoicing'),
470
+        'TWD' => __('New Taiwan Dollar', 'invoicing'),
471
+        'TZS' => __('Tanzanian Shilling', 'invoicing'),
472
+        'UAH' => __('Ukrainian Hryvnia', 'invoicing'),
473
+        'UGX' => __('Ugandan Shilling', 'invoicing'),
474
+        'UYU' => __('Uruguayan Peso', 'invoicing'),
475
+        'UZS' => __('Uzbekistani Som', 'invoicing'),
476
+        'VEF' => __('Venezuelan Bol&iacute;var', 'invoicing'),
477
+        'VND' => __('Vietnamese Dong', 'invoicing'),
478
+        'VUV' => __('Vanuatu Vatu', 'invoicing'),
479
+        'WST' => __('Samoan Tala', 'invoicing'),
480
+        'XAF' => __('Central African CFA Franc', 'invoicing'),
481
+        'XCD' => __('East Caribbean Dollar', 'invoicing'),
482
+        'XOF' => __('West African CFA Franc', 'invoicing'),
483
+        'XPF' => __('CFP Franc', 'invoicing'),
484
+        'YER' => __('Yemeni Rial', 'invoicing'),
485
+        'ZAR' => __('South African Rand', 'invoicing'),
486
+        'ZMW' => __('Zambian Kwacha', 'invoicing'),
487 487
     );
488 488
     
489 489
     //asort( $currencies ); // this
490 490
 
491
-    return apply_filters( 'wpinv_currencies', $currencies );
491
+    return apply_filters('wpinv_currencies', $currencies);
492 492
 }
493 493
 
494
-function wpinv_price( $amount = '', $currency = '' ) {
495
-    if( empty( $currency ) ) {
494
+function wpinv_price($amount = '', $currency = '') {
495
+    if (empty($currency)) {
496 496
         $currency = wpinv_get_currency();
497 497
     }
498 498
 
@@ -500,14 +500,14 @@  discard block
 block discarded – undo
500 500
 
501 501
     $negative = $amount < 0;
502 502
 
503
-    if ( $negative ) {
504
-        $amount = substr( $amount, 1 );
503
+    if ($negative) {
504
+        $amount = substr($amount, 1);
505 505
     }
506 506
 
507
-    $symbol = wpinv_currency_symbol( $currency );
507
+    $symbol = wpinv_currency_symbol($currency);
508 508
 
509
-    if ( $position == 'left' || $position == 'left_space' ) {
510
-        switch ( $currency ) {
509
+    if ($position == 'left' || $position == 'left_space') {
510
+        switch ($currency) {
511 511
             case "GBP" :
512 512
             case "BRL" :
513 513
             case "EUR" :
@@ -519,15 +519,15 @@  discard block
 block discarded – undo
519 519
             case "NZD" :
520 520
             case "SGD" :
521 521
             case "JPY" :
522
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
522
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
523 523
                 break;
524 524
             default :
525 525
                 //$price = $currency . ' ' . $amount;
526
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
526
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
527 527
                 break;
528 528
         }
529 529
     } else {
530
-        switch ( $currency ) {
530
+        switch ($currency) {
531 531
             case "GBP" :
532 532
             case "BRL" :
533 533
             case "EUR" :
@@ -538,83 +538,83 @@  discard block
 block discarded – undo
538 538
             case "MXN" :
539 539
             case "SGD" :
540 540
             case "JPY" :
541
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
541
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
542 542
                 break;
543 543
             default :
544 544
                 //$price = $amount . ' ' . $currency;
545
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
545
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
546 546
                 break;
547 547
         }
548 548
     }
549 549
     
550
-    if ( $negative ) {
550
+    if ($negative) {
551 551
         $price = '-' . $price;
552 552
     }
553 553
     
554
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
554
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
555 555
 
556 556
     return $price;
557 557
 }
558 558
 
559
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
559
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
560 560
     $thousands_sep = wpinv_thousands_separator();
561 561
     $decimal_sep   = wpinv_decimal_separator();
562 562
 
563
-    if ( $decimals === NULL ) {
563
+    if ($decimals === NULL) {
564 564
         $decimals = wpinv_decimals();
565 565
     }
566 566
 
567
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
568
-        $whole = substr( $amount, 0, $sep_found );
569
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
567
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
568
+        $whole = substr($amount, 0, $sep_found);
569
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
570 570
         $amount = $whole . '.' . $part;
571 571
     }
572 572
 
573
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
574
-        $amount = str_replace( ',', '', $amount );
573
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
574
+        $amount = str_replace(',', '', $amount);
575 575
     }
576 576
 
577
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
578
-        $amount = str_replace( ' ', '', $amount );
577
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
578
+        $amount = str_replace(' ', '', $amount);
579 579
     }
580 580
 
581
-    if ( empty( $amount ) ) {
581
+    if (empty($amount)) {
582 582
         $amount = 0;
583 583
     }
584 584
     
585
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
586
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
585
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
586
+    $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep);
587 587
     
588
-    if ( $calculate ) {
589
-        if ( $thousands_sep === "," ) {
590
-            $formatted = str_replace( ",", "", $formatted );
588
+    if ($calculate) {
589
+        if ($thousands_sep === ",") {
590
+            $formatted = str_replace(",", "", $formatted);
591 591
         }
592 592
         
593
-        if ( $decimal_sep === "," ) {
594
-            $formatted = str_replace( ",", ".", $formatted );
593
+        if ($decimal_sep === ",") {
594
+            $formatted = str_replace(",", ".", $formatted);
595 595
         }
596 596
     }
597 597
 
598
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
598
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
599 599
 }
600
-add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
600
+add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1);
601 601
 
602
-function wpinv_sanitize_key( $key ) {
602
+function wpinv_sanitize_key($key) {
603 603
     $raw_key = $key;
604
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
604
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
605 605
 
606
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
606
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
607 607
 }
608 608
 
609
-function wpinv_get_file_extension( $str ) {
610
-    $parts = explode( '.', $str );
611
-    return end( $parts );
609
+function wpinv_get_file_extension($str) {
610
+    $parts = explode('.', $str);
611
+    return end($parts);
612 612
 }
613 613
 
614
-function wpinv_string_is_image_url( $str ) {
615
-    $ext = wpinv_get_file_extension( $str );
614
+function wpinv_string_is_image_url($str) {
615
+    $ext = wpinv_get_file_extension($str);
616 616
 
617
-    switch ( strtolower( $ext ) ) {
617
+    switch (strtolower($ext)) {
618 618
         case 'jpeg';
619 619
         case 'jpg';
620 620
             $return = true;
@@ -630,32 +630,32 @@  discard block
 block discarded – undo
630 630
             break;
631 631
     }
632 632
 
633
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
633
+    return (bool)apply_filters('wpinv_string_is_image', $return, $str);
634 634
 }
635 635
 
636
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
637
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
636
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
637
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
638 638
     
639
-    if ( true === $should_log ) {
639
+    if (true === $should_log) {
640 640
         $label = '';
641
-        if ( $file && $file !== '' ) {
642
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
641
+        if ($file && $file !== '') {
642
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
643 643
         }
644 644
         
645
-        if ( $title && $title !== '' ) {
645
+        if ($title && $title !== '') {
646 646
             $label = $label !== '' ? $label . ' ' : '';
647 647
             $label .= $title . ' ';
648 648
         }
649 649
         
650
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
650
+        $label = $label !== '' ? trim($label) . ' : ' : '';
651 651
         
652
-        if ( is_array( $log ) || is_object( $log ) ) {
653
-            error_log( $label . print_r( $log, true ) );
652
+        if (is_array($log) || is_object($log)) {
653
+            error_log($label . print_r($log, true));
654 654
         } else {
655
-            error_log( $label . $log );
655
+            error_log($label . $log);
656 656
         }
657 657
         
658
-        if ( $exit ) {
658
+        if ($exit) {
659 659
             exit;
660 660
         }
661 661
     }
@@ -663,65 +663,65 @@  discard block
 block discarded – undo
663 663
 
664 664
 function wpinv_is_ajax_disabled() {
665 665
     $retval = false;
666
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
666
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
667 667
 }
668 668
 
669
-function wpinv_get_current_page_url( $nocache = false ) {
669
+function wpinv_get_current_page_url($nocache = false) {
670 670
     global $wp;
671 671
 
672
-    if ( get_option( 'permalink_structure' ) ) {
673
-        $base = trailingslashit( home_url( $wp->request ) );
672
+    if (get_option('permalink_structure')) {
673
+        $base = trailingslashit(home_url($wp->request));
674 674
     } else {
675
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
676
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
675
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
676
+        $base = remove_query_arg(array('post_type', 'name'), $base);
677 677
     }
678 678
 
679 679
     $scheme = is_ssl() ? 'https' : 'http';
680
-    $uri    = set_url_scheme( $base, $scheme );
680
+    $uri    = set_url_scheme($base, $scheme);
681 681
 
682
-    if ( is_front_page() ) {
683
-        $uri = home_url( '/' );
684
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
682
+    if (is_front_page()) {
683
+        $uri = home_url('/');
684
+    } elseif (wpinv_is_checkout(array(), false)) {
685 685
         $uri = wpinv_get_checkout_uri();
686 686
     }
687 687
 
688
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
688
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
689 689
 
690
-    if ( $nocache ) {
691
-        $uri = wpinv_add_cache_busting( $uri );
690
+    if ($nocache) {
691
+        $uri = wpinv_add_cache_busting($uri);
692 692
     }
693 693
 
694 694
     return $uri;
695 695
 }
696 696
 
697 697
 function wpinv_get_php_arg_separator_output() {
698
-	return ini_get( 'arg_separator.output' );
698
+	return ini_get('arg_separator.output');
699 699
 }
700 700
 
701
-function wpinv_rgb_from_hex( $color ) {
702
-    $color = str_replace( '#', '', $color );
701
+function wpinv_rgb_from_hex($color) {
702
+    $color = str_replace('#', '', $color);
703 703
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
704
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
704
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
705 705
 
706 706
     $rgb      = array();
707
-    $rgb['R'] = hexdec( $color{0}.$color{1} );
708
-    $rgb['G'] = hexdec( $color{2}.$color{3} );
709
-    $rgb['B'] = hexdec( $color{4}.$color{5} );
707
+    $rgb['R'] = hexdec($color{0} . $color{1} );
708
+    $rgb['G'] = hexdec($color{2} . $color{3} );
709
+    $rgb['B'] = hexdec($color{4} . $color{5} );
710 710
 
711 711
     return $rgb;
712 712
 }
713 713
 
714
-function wpinv_hex_darker( $color, $factor = 30 ) {
715
-    $base  = wpinv_rgb_from_hex( $color );
714
+function wpinv_hex_darker($color, $factor = 30) {
715
+    $base  = wpinv_rgb_from_hex($color);
716 716
     $color = '#';
717 717
 
718
-    foreach ( $base as $k => $v ) {
718
+    foreach ($base as $k => $v) {
719 719
         $amount      = $v / 100;
720
-        $amount      = round( $amount * $factor );
720
+        $amount      = round($amount * $factor);
721 721
         $new_decimal = $v - $amount;
722 722
 
723
-        $new_hex_component = dechex( $new_decimal );
724
-        if ( strlen( $new_hex_component ) < 2 ) {
723
+        $new_hex_component = dechex($new_decimal);
724
+        if (strlen($new_hex_component) < 2) {
725 725
             $new_hex_component = "0" . $new_hex_component;
726 726
         }
727 727
         $color .= $new_hex_component;
@@ -730,18 +730,18 @@  discard block
 block discarded – undo
730 730
     return $color;
731 731
 }
732 732
 
733
-function wpinv_hex_lighter( $color, $factor = 30 ) {
734
-    $base  = wpinv_rgb_from_hex( $color );
733
+function wpinv_hex_lighter($color, $factor = 30) {
734
+    $base  = wpinv_rgb_from_hex($color);
735 735
     $color = '#';
736 736
 
737
-    foreach ( $base as $k => $v ) {
737
+    foreach ($base as $k => $v) {
738 738
         $amount      = 255 - $v;
739 739
         $amount      = $amount / 100;
740
-        $amount      = round( $amount * $factor );
740
+        $amount      = round($amount * $factor);
741 741
         $new_decimal = $v + $amount;
742 742
 
743
-        $new_hex_component = dechex( $new_decimal );
744
-        if ( strlen( $new_hex_component ) < 2 ) {
743
+        $new_hex_component = dechex($new_decimal);
744
+        if (strlen($new_hex_component) < 2) {
745 745
             $new_hex_component = "0" . $new_hex_component;
746 746
         }
747 747
         $color .= $new_hex_component;
@@ -750,22 +750,22 @@  discard block
 block discarded – undo
750 750
     return $color;
751 751
 }
752 752
 
753
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
754
-    $hex = str_replace( '#', '', $color );
753
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
754
+    $hex = str_replace('#', '', $color);
755 755
 
756
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
757
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
758
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
756
+    $c_r = hexdec(substr($hex, 0, 2));
757
+    $c_g = hexdec(substr($hex, 2, 2));
758
+    $c_b = hexdec(substr($hex, 4, 2));
759 759
 
760
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
760
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
761 761
 
762 762
     return $brightness > 155 ? $dark : $light;
763 763
 }
764 764
 
765
-function wpinv_format_hex( $hex ) {
766
-    $hex = trim( str_replace( '#', '', $hex ) );
765
+function wpinv_format_hex($hex) {
766
+    $hex = trim(str_replace('#', '', $hex));
767 767
 
768
-    if ( strlen( $hex ) == 3 ) {
768
+    if (strlen($hex) == 3) {
769 769
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
770 770
     }
771 771
 
@@ -785,12 +785,12 @@  discard block
 block discarded – undo
785 785
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
786 786
  * @return string
787 787
  */
788
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
789
-    if ( function_exists( 'mb_strimwidth' ) ) {
790
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
788
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
789
+    if (function_exists('mb_strimwidth')) {
790
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
791 791
     }
792 792
     
793
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
793
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
794 794
 }
795 795
 
796 796
 /**
@@ -802,28 +802,28 @@  discard block
 block discarded – undo
802 802
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
803 803
  * @return int Returns the number of characters in string.
804 804
  */
805
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
806
-    if ( function_exists( 'mb_strlen' ) ) {
807
-        return mb_strlen( $str, $encoding );
805
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
806
+    if (function_exists('mb_strlen')) {
807
+        return mb_strlen($str, $encoding);
808 808
     }
809 809
         
810
-    return strlen( $str );
810
+    return strlen($str);
811 811
 }
812 812
 
813
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
814
-    if ( function_exists( 'mb_strtolower' ) ) {
815
-        return mb_strtolower( $str, $encoding );
813
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
814
+    if (function_exists('mb_strtolower')) {
815
+        return mb_strtolower($str, $encoding);
816 816
     }
817 817
     
818
-    return strtolower( $str );
818
+    return strtolower($str);
819 819
 }
820 820
 
821
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
822
-    if ( function_exists( 'mb_strtoupper' ) ) {
823
-        return mb_strtoupper( $str, $encoding );
821
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
822
+    if (function_exists('mb_strtoupper')) {
823
+        return mb_strtoupper($str, $encoding);
824 824
     }
825 825
     
826
-    return strtoupper( $str );
826
+    return strtoupper($str);
827 827
 }
828 828
 
829 829
 /**
@@ -837,12 +837,12 @@  discard block
 block discarded – undo
837 837
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
838 838
  * @return int Returns the position of the first occurrence of search in the string.
839 839
  */
840
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
841
-    if ( function_exists( 'mb_strpos' ) ) {
842
-        return mb_strpos( $str, $find, $offset, $encoding );
840
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
841
+    if (function_exists('mb_strpos')) {
842
+        return mb_strpos($str, $find, $offset, $encoding);
843 843
     }
844 844
         
845
-    return strpos( $str, $find, $offset );
845
+    return strpos($str, $find, $offset);
846 846
 }
847 847
 
848 848
 /**
@@ -856,12 +856,12 @@  discard block
 block discarded – undo
856 856
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
857 857
  * @return int Returns the position of the last occurrence of search.
858 858
  */
859
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
860
-    if ( function_exists( 'mb_strrpos' ) ) {
861
-        return mb_strrpos( $str, $find, $offset, $encoding );
859
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
860
+    if (function_exists('mb_strrpos')) {
861
+        return mb_strrpos($str, $find, $offset, $encoding);
862 862
     }
863 863
         
864
-    return strrpos( $str, $find, $offset );
864
+    return strrpos($str, $find, $offset);
865 865
 }
866 866
 
867 867
 /**
@@ -876,16 +876,16 @@  discard block
 block discarded – undo
876 876
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
877 877
  * @return string
878 878
  */
879
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
880
-    if ( function_exists( 'mb_substr' ) ) {
881
-        if ( $length === null ) {
882
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
879
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
880
+    if (function_exists('mb_substr')) {
881
+        if ($length === null) {
882
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
883 883
         } else {
884
-            return mb_substr( $str, $start, $length, $encoding );
884
+            return mb_substr($str, $start, $length, $encoding);
885 885
         }
886 886
     }
887 887
         
888
-    return substr( $str, $start, $length );
888
+    return substr($str, $start, $length);
889 889
 }
890 890
 
891 891
 /**
@@ -897,48 +897,48 @@  discard block
 block discarded – undo
897 897
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
898 898
  * @return string The width of string.
899 899
  */
900
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
901
-    if ( function_exists( 'mb_strwidth' ) ) {
902
-        return mb_strwidth( $str, $encoding );
900
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
901
+    if (function_exists('mb_strwidth')) {
902
+        return mb_strwidth($str, $encoding);
903 903
     }
904 904
     
905
-    return wpinv_utf8_strlen( $str, $encoding );
905
+    return wpinv_utf8_strlen($str, $encoding);
906 906
 }
907 907
 
908
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
909
-    if ( function_exists( 'mb_strlen' ) ) {
910
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
908
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
909
+    if (function_exists('mb_strlen')) {
910
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
911 911
         $str_end = "";
912 912
         
913
-        if ( $lower_str_end ) {
914
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
913
+        if ($lower_str_end) {
914
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
915 915
         } else {
916
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
916
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
917 917
         }
918 918
 
919 919
         return $first_letter . $str_end;
920 920
     }
921 921
     
922
-    return ucfirst( $str );
922
+    return ucfirst($str);
923 923
 }
924 924
 
925
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
926
-    if ( function_exists( 'mb_convert_case' ) ) {
927
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
925
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
926
+    if (function_exists('mb_convert_case')) {
927
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
928 928
     }
929 929
     
930
-    return ucwords( $str );
930
+    return ucwords($str);
931 931
 }
932 932
 
933
-function wpinv_period_in_days( $period, $unit ) {
934
-    $period = absint( $period );
933
+function wpinv_period_in_days($period, $unit) {
934
+    $period = absint($period);
935 935
     
936
-    if ( $period > 0 ) {
937
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
936
+    if ($period > 0) {
937
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
938 938
             $period = $period * 7;
939
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
939
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
940 940
             $period = $period * 30;
941
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
941
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
942 942
             $period = $period * 365;
943 943
         }
944 944
     }
@@ -946,12 +946,12 @@  discard block
 block discarded – undo
946 946
     return $period;
947 947
 }
948 948
 
949
-function wpinv_cal_days_in_month( $calendar, $month, $year ) {
950
-    if ( function_exists( 'cal_days_in_month' ) ) {
951
-        return cal_days_in_month( $calendar, $month, $year );
949
+function wpinv_cal_days_in_month($calendar, $month, $year) {
950
+    if (function_exists('cal_days_in_month')) {
951
+        return cal_days_in_month($calendar, $month, $year);
952 952
     }
953 953
 
954 954
     // Fallback in case the calendar extension is not loaded in PHP
955 955
     // Only supports Gregorian calendar
956
-    return date( 't', mktime( 0, 0, 0, $month, 1, $year ) );
956
+    return date('t', mktime(0, 0, 0, $month, 1, $year));
957 957
 }
Please login to merge, or discard this patch.
includes/class-wpinv-cache-helper.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -14,18 +14,18 @@  discard block
 block discarded – undo
14 14
      * Hook in methods.
15 15
      */
16 16
     public static function init() {
17
-        add_action( 'init', array( __CLASS__, 'init_hooks' ), 0 );
18
-        add_action( 'admin_notices', array( __CLASS__, 'notices' ) );
17
+        add_action('init', array(__CLASS__, 'init_hooks'), 0);
18
+        add_action('admin_notices', array(__CLASS__, 'notices'));
19 19
     }
20 20
 
21 21
     public static function init_hooks() {
22
-        if ( false === ( $page_uris = get_transient( 'wpinv_cache_excluded_uris' ) ) ) {
23
-            $checkout_page = wpinv_get_option( 'checkout_page', '' );
24
-            $success_page  = wpinv_get_option( 'success_page', '' );
25
-            $failure_page  = wpinv_get_option( 'failure_page', '' );
26
-            $history_page  = wpinv_get_option( 'invoice_history_page', '' );
27
-            $subscr_page   = wpinv_get_option( 'invoice_subscription_page', '' );
28
-            if ( empty( $checkout_page ) || empty( $success_page ) || empty( $failure_page ) || empty( $history_page ) || empty( $subscr_page ) ) {
22
+        if (false === ($page_uris = get_transient('wpinv_cache_excluded_uris'))) {
23
+            $checkout_page = wpinv_get_option('checkout_page', '');
24
+            $success_page  = wpinv_get_option('success_page', '');
25
+            $failure_page  = wpinv_get_option('failure_page', '');
26
+            $history_page  = wpinv_get_option('invoice_history_page', '');
27
+            $subscr_page   = wpinv_get_option('invoice_subscription_page', '');
28
+            if (empty($checkout_page) || empty($success_page) || empty($failure_page) || empty($history_page) || empty($subscr_page)) {
29 29
                 return;
30 30
             }
31 31
 
@@ -39,34 +39,34 @@  discard block
 block discarded – undo
39 39
             $page_uris[] = 'p=' . $subscr_page;
40 40
 
41 41
             // Exclude permalinks
42
-            $checkout_page  = get_post( $checkout_page );
43
-            $success_page   = get_post( $success_page );
44
-            $failure_page   = get_post( $failure_page );
45
-            $history_page   = get_post( $history_page );
46
-            $subscr_page    = get_post( $subscr_page );
42
+            $checkout_page  = get_post($checkout_page);
43
+            $success_page   = get_post($success_page);
44
+            $failure_page   = get_post($failure_page);
45
+            $history_page   = get_post($history_page);
46
+            $subscr_page    = get_post($subscr_page);
47 47
 
48
-            if ( ! is_null( $checkout_page ) ) {
48
+            if (!is_null($checkout_page)) {
49 49
                 $page_uris[] = '/' . $checkout_page->post_name;
50 50
             }
51
-            if ( ! is_null( $success_page ) ) {
51
+            if (!is_null($success_page)) {
52 52
                 $page_uris[] = '/' . $success_page->post_name;
53 53
             }
54
-            if ( ! is_null( $failure_page ) ) {
54
+            if (!is_null($failure_page)) {
55 55
                 $page_uris[] = '/' . $failure_page->post_name;
56 56
             }
57
-            if ( ! is_null( $history_page ) ) {
57
+            if (!is_null($history_page)) {
58 58
                 $page_uris[] = '/' . $history_page->post_name;
59 59
             }
60
-            if ( ! is_null( $subscr_page ) ) {
60
+            if (!is_null($subscr_page)) {
61 61
                 $page_uris[] = '/' . $subscr_page->post_name;
62 62
             }
63 63
 
64
-            set_transient( 'wpinv_cache_excluded_uris', $page_uris );
64
+            set_transient('wpinv_cache_excluded_uris', $page_uris);
65 65
         }
66 66
 
67
-        if ( is_array( $page_uris ) ) {
68
-            foreach( $page_uris as $uri ) {
69
-                if ( strstr( $_SERVER['REQUEST_URI'], $uri ) ) {
67
+        if (is_array($page_uris)) {
68
+            foreach ($page_uris as $uri) {
69
+                if (strstr($_SERVER['REQUEST_URI'], $uri)) {
70 70
                     self::nocache();
71 71
                     break;
72 72
                 }
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
      * @access private
80 80
      */
81 81
     private static function nocache() {
82
-        if ( ! defined( 'DONOTCACHEPAGE' ) ) {
83
-            define( "DONOTCACHEPAGE", true );
82
+        if (!defined('DONOTCACHEPAGE')) {
83
+            define("DONOTCACHEPAGE", true);
84 84
         }
85
-        if ( ! defined( 'DONOTCACHEOBJECT' ) ) {
86
-            define( "DONOTCACHEOBJECT", true );
85
+        if (!defined('DONOTCACHEOBJECT')) {
86
+            define("DONOTCACHEOBJECT", true);
87 87
         }
88
-        if ( ! defined( 'DONOTCACHEDB' ) ) {
89
-            define( "DONOTCACHEDB", true );
88
+        if (!defined('DONOTCACHEDB')) {
89
+            define("DONOTCACHEDB", true);
90 90
         }
91 91
         nocache_headers();
92 92
     }
@@ -95,18 +95,18 @@  discard block
 block discarded – undo
95 95
      * notices function.
96 96
      */
97 97
     public static function notices() {
98
-        if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) {
98
+        if (!function_exists('w3tc_pgcache_flush') || !function_exists('w3_instance')) {
99 99
             return;
100 100
         }
101 101
 
102
-        $config   = w3_instance( 'W3_Config' );
103
-        $enabled  = $config->get_integer( 'dbcache.enabled' );
104
-        $settings = array_map( 'trim', $config->get_array( 'dbcache.reject.sql' ) );
102
+        $config   = w3_instance('W3_Config');
103
+        $enabled  = $config->get_integer('dbcache.enabled');
104
+        $settings = array_map('trim', $config->get_array('dbcache.reject.sql'));
105 105
 
106
-        if ( $enabled && ! in_array( '_wp_session_', $settings ) ) {
106
+        if ($enabled && !in_array('_wp_session_', $settings)) {
107 107
             ?>
108 108
             <div class="error">
109
-                <p><?php printf( __( 'In order for <strong>database caching</strong> to work with Invoicing you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'invoicing' ), '<code>_wp_session_</code>', admin_url( 'admin.php?page=w3tc_dbcache' ) ); ?></p>
109
+                <p><?php printf(__('In order for <strong>database caching</strong> to work with Invoicing you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'invoicing'), '<code>_wp_session_</code>', admin_url('admin.php?page=w3tc_dbcache')); ?></p>
110 110
             </div>
111 111
             <?php
112 112
         }
Please login to merge, or discard this patch.
includes/class-wpinv-shortcodes.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -16,41 +16,41 @@  discard block
 block discarded – undo
16 16
             'wpinv_subscriptions'  => __CLASS__ . '::subscriptions',
17 17
         );
18 18
 
19
-        foreach ( $shortcodes as $shortcode => $function ) {
20
-            add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), $function );
19
+        foreach ($shortcodes as $shortcode => $function) {
20
+            add_shortcode(apply_filters("{$shortcode}_shortcode_tag", $shortcode), $function);
21 21
         }
22 22
         
23
-        add_shortcode( 'wpinv_messages', __CLASS__ . '::messages' );
23
+        add_shortcode('wpinv_messages', __CLASS__ . '::messages');
24 24
     }
25 25
 
26
-    public static function shortcode_wrapper( $function, $atts = array(), $content = null, $wrapper = array( 'class' => 'wpi-g', 'before' => null, 'after' => null ) ) {
26
+    public static function shortcode_wrapper($function, $atts = array(), $content = null, $wrapper = array('class' => 'wpi-g', 'before' => null, 'after' => null)) {
27 27
         ob_start();
28 28
 
29
-        echo empty( $wrapper['before'] ) ? '<div class="' . esc_attr( $wrapper['class'] ) . '">' : $wrapper['before'];
30
-        call_user_func( $function, $atts, $content );
31
-        echo empty( $wrapper['after'] ) ? '</div>' : $wrapper['after'];
29
+        echo empty($wrapper['before']) ? '<div class="' . esc_attr($wrapper['class']) . '">' : $wrapper['before'];
30
+        call_user_func($function, $atts, $content);
31
+        echo empty($wrapper['after']) ? '</div>' : $wrapper['after'];
32 32
 
33 33
         return ob_get_clean();
34 34
     }
35 35
 
36
-    public static function checkout( $atts = array(), $content = null ) {
37
-        return self::shortcode_wrapper( array( __CLASS__, 'checkout_output' ), $atts, $content );
36
+    public static function checkout($atts = array(), $content = null) {
37
+        return self::shortcode_wrapper(array(__CLASS__, 'checkout_output'), $atts, $content);
38 38
     }
39 39
     
40
-    public static function checkout_output( $atts = array(), $content = null ) {
41
-        do_action( 'wpinv_checkout_content_before' );
42
-        echo wpinv_checkout_form( $atts, $content );
43
-        do_action( 'wpinv_checkout_content_after' );
40
+    public static function checkout_output($atts = array(), $content = null) {
41
+        do_action('wpinv_checkout_content_before');
42
+        echo wpinv_checkout_form($atts, $content);
43
+        do_action('wpinv_checkout_content_after');
44 44
     }
45 45
 
46
-    public static function messages( $atts, $content = null ) {
46
+    public static function messages($atts, $content = null) {
47 47
         ob_start();
48 48
         wpinv_print_errors();
49 49
         return '<div class="wpinv">' . ob_get_clean() . '</div>';
50 50
     }
51 51
     
52
-    public static function history( $atts, $content = null ) {
53
-        return self::shortcode_wrapper( array( __CLASS__, 'history_output' ), $atts );
52
+    public static function history($atts, $content = null) {
53
+        return self::shortcode_wrapper(array(__CLASS__, 'history_output'), $atts);
54 54
     }
55 55
 
56 56
     /**
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
      *
59 59
      * @param array $atts
60 60
      */
61
-    public static function history_output( $atts ) {
62
-        do_action( 'wpinv_before_user_invoice_history' );
63
-        wpinv_get_template_part( 'wpinv-invoice-history', $atts );
64
-        do_action( 'wpinv_after_user_invoice_history' );
61
+    public static function history_output($atts) {
62
+        do_action('wpinv_before_user_invoice_history');
63
+        wpinv_get_template_part('wpinv-invoice-history', $atts);
64
+        do_action('wpinv_after_user_invoice_history');
65 65
     }
66 66
     
67
-    public static function success( $atts, $content = null ) {
68
-        return self::shortcode_wrapper( array( __CLASS__, 'success_output' ), $atts, $content );
67
+    public static function success($atts, $content = null) {
68
+        return self::shortcode_wrapper(array(__CLASS__, 'success_output'), $atts, $content);
69 69
     }
70 70
     
71 71
     /**
@@ -73,31 +73,31 @@  discard block
 block discarded – undo
73 73
      *
74 74
      * @param array $atts
75 75
      */
76
-    public static function success_output( $atts, $content = null ) {
77
-        do_action( 'wpinv_success_content_before' );
78
-        echo wpinv_payment_receipt( $atts, $content );
79
-        do_action( 'wpinv_success_content_after' );
76
+    public static function success_output($atts, $content = null) {
77
+        do_action('wpinv_success_content_before');
78
+        echo wpinv_payment_receipt($atts, $content);
79
+        do_action('wpinv_success_content_after');
80 80
     }
81 81
 
82
-    public static function buy( $atts, $content = null ) {
83
-        $a = shortcode_atts( array(
82
+    public static function buy($atts, $content = null) {
83
+        $a = shortcode_atts(array(
84 84
             'items'     => '', // should be used like: item_id|quantity,item_id|quantity,item_id|quantity
85
-            'title'     => __( 'Buy Now', 'invoicing' ), // the button title
85
+            'title'     => __('Buy Now', 'invoicing'), // the button title
86 86
             'post_id'   => '', // any related post_id
87
-        ), $atts );
87
+        ), $atts);
88 88
 
89
-        $post_id = isset( $a['post_id'] ) ? (int)$a['post_id'] : '';
89
+        $post_id = isset($a['post_id']) ? (int)$a['post_id'] : '';
90 90
 
91 91
         $html = '<div class="wpi-buy-button-wrapper wpi-g">';
92 92
         $html .= '<button class="button button-primary wpi-buy-button" type="button" onclick="wpi_buy(this,\'' . $a['items'] . '\',' . $post_id . ');">' . $a['title'] . '</button>';
93
-        $html .= wp_nonce_field( 'wpinv_buy_items', 'wpinv_buy_nonce', true, false );
93
+        $html .= wp_nonce_field('wpinv_buy_items', 'wpinv_buy_nonce', true, false);
94 94
         $html .= '</div>';
95 95
 
96 96
         return $html;
97 97
     }
98 98
     
99
-    public static function subscriptions( $atts, $content = null ) {
100
-        return self::shortcode_wrapper( array( __CLASS__, 'subscriptions_output' ), $atts );
99
+    public static function subscriptions($atts, $content = null) {
100
+        return self::shortcode_wrapper(array(__CLASS__, 'subscriptions_output'), $atts);
101 101
     }
102 102
 
103 103
     /**
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
      *
106 106
      * @param array $atts
107 107
      */
108
-    public static function subscriptions_output( $atts ) {
109
-        do_action( 'wpinv_before_user_subscriptions' );
110
-        wpinv_get_template_part( 'wpinv-subscriptions-history', $atts );
111
-        do_action( 'wpinv_after_user_subscriptions' );
108
+    public static function subscriptions_output($atts) {
109
+        do_action('wpinv_before_user_subscriptions');
110
+        wpinv_get_template_part('wpinv-subscriptions-history', $atts);
111
+        do_action('wpinv_after_user_subscriptions');
112 112
     }
113 113
 }
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 1 patch
Spacing   +470 added lines, -470 removed lines patch added patch discarded remove patch
@@ -7,90 +7,90 @@  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_discount_types() {
15 15
     $discount_types = array(
16
-                        'percent'   => __( 'Percentage', 'invoicing' ),
17
-                        'flat'     => __( 'Flat Amount', 'invoicing' ),
16
+                        'percent'   => __('Percentage', 'invoicing'),
17
+                        'flat'     => __('Flat Amount', 'invoicing'),
18 18
                     );
19
-    return (array)apply_filters( 'wpinv_discount_types', $discount_types );
19
+    return (array)apply_filters('wpinv_discount_types', $discount_types);
20 20
 }
21 21
 
22
-function wpinv_get_discount_type_name( $type = '' ) {
22
+function wpinv_get_discount_type_name($type = '') {
23 23
     $types = wpinv_get_discount_types();
24
-    return isset( $types[ $type ] ) ? $types[ $type ] : '';
24
+    return isset($types[$type]) ? $types[$type] : '';
25 25
 }
26 26
 
27
-function wpinv_delete_discount( $data ) {
28
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
29
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
27
+function wpinv_delete_discount($data) {
28
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
29
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
30 30
     }
31 31
 
32
-    if( ! current_user_can( 'manage_options' ) ) {
33
-        wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
32
+    if (!current_user_can('manage_options')) {
33
+        wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
34 34
     }
35 35
 
36 36
     $discount_id = $data['discount'];
37
-    wpinv_remove_discount( $discount_id );
37
+    wpinv_remove_discount($discount_id);
38 38
 }
39
-add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' );
39
+add_action('wpinv_delete_discount', 'wpinv_delete_discount');
40 40
 
41
-function wpinv_activate_discount( $data ) {
42
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
43
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
41
+function wpinv_activate_discount($data) {
42
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
43
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
44 44
     }
45 45
 
46
-    if( ! current_user_can( 'manage_options' ) ) {
47
-        wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
46
+    if (!current_user_can('manage_options')) {
47
+        wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
48 48
     }
49 49
 
50
-    $id = absint( $data['discount'] );
51
-    wpinv_update_discount_status( $id, 'publish' );
50
+    $id = absint($data['discount']);
51
+    wpinv_update_discount_status($id, 'publish');
52 52
 }
53
-add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' );
53
+add_action('wpinv_activate_discount', 'wpinv_activate_discount');
54 54
 
55
-function wpinv_deactivate_discount( $data ) {
56
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
57
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_deactivate_discount($data) {
56
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
57
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
 
60
-    if( ! current_user_can( 'manage_options' ) ) {
61
-        wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) );
60
+    if (!current_user_can('manage_options')) {
61
+        wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403));
62 62
     }
63 63
 
64
-    $id = absint( $data['discount'] );
65
-    wpinv_update_discount_status( $id, 'pending' );
64
+    $id = absint($data['discount']);
65
+    wpinv_update_discount_status($id, 'pending');
66 66
 }
67
-add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' );
67
+add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount');
68 68
 
69
-function wpinv_get_discounts( $args = array() ) {
69
+function wpinv_get_discounts($args = array()) {
70 70
     $defaults = array(
71 71
         'post_type'      => 'wpi_discount',
72 72
         'posts_per_page' => 20,
73 73
         'paged'          => null,
74
-        'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
74
+        'post_status'    => array('publish', 'pending', 'draft', 'expired')
75 75
     );
76 76
 
77
-    $args = wp_parse_args( $args, $defaults );
77
+    $args = wp_parse_args($args, $defaults);
78 78
 
79
-    $discounts = get_posts( $args );
79
+    $discounts = get_posts($args);
80 80
 
81
-    if ( $discounts ) {
81
+    if ($discounts) {
82 82
         return $discounts;
83 83
     }
84 84
 
85
-    if( ! $discounts && ! empty( $args['s'] ) ) {
85
+    if (!$discounts && !empty($args['s'])) {
86 86
         $args['meta_key']     = '_wpi_discount_code';
87 87
         $args['meta_value']   = $args['s'];
88 88
         $args['meta_compare'] = 'LIKE';
89
-        unset( $args['s'] );
90
-        $discounts = get_posts( $args );
89
+        unset($args['s']);
90
+        $discounts = get_posts($args);
91 91
     }
92 92
 
93
-    if( $discounts ) {
93
+    if ($discounts) {
94 94
         return $discounts;
95 95
     }
96 96
 
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 
103 103
     $discounts  = wpinv_get_discounts();
104 104
 
105
-    if ( $discounts) {
106
-        foreach ( $discounts as $discount ) {
107
-            if ( wpinv_is_discount_active( $discount->ID ) ) {
105
+    if ($discounts) {
106
+        foreach ($discounts as $discount) {
107
+            if (wpinv_is_discount_active($discount->ID)) {
108 108
                 $has_active = true;
109 109
                 break;
110 110
             }
@@ -113,38 +113,38 @@  discard block
 block discarded – undo
113 113
     return $has_active;
114 114
 }
115 115
 
116
-function wpinv_get_discount( $discount_id = 0 ) {
117
-    if( empty( $discount_id ) ) {
116
+function wpinv_get_discount($discount_id = 0) {
117
+    if (empty($discount_id)) {
118 118
         return false;
119 119
     }
120 120
     
121
-    if ( get_post_type( $discount_id ) != 'wpi_discount' ) {
121
+    if (get_post_type($discount_id) != 'wpi_discount') {
122 122
         return false;
123 123
     }
124 124
 
125
-    $discount = get_post( $discount_id );
125
+    $discount = get_post($discount_id);
126 126
 
127 127
     return $discount;
128 128
 }
129 129
 
130
-function wpinv_get_discount_by_code( $code = '' ) {
131
-    if( empty( $code ) || ! is_string( $code ) ) {
130
+function wpinv_get_discount_by_code($code = '') {
131
+    if (empty($code) || !is_string($code)) {
132 132
         return false;
133 133
     }
134 134
 
135
-    return wpinv_get_discount_by( 'code', $code );
135
+    return wpinv_get_discount_by('code', $code);
136 136
 }
137 137
 
138
-function wpinv_get_discount_by( $field = '', $value = '' ) {
139
-    if( empty( $field ) || empty( $value ) ) {
138
+function wpinv_get_discount_by($field = '', $value = '') {
139
+    if (empty($field) || empty($value)) {
140 140
         return false;
141 141
     }
142 142
 
143
-    if( ! is_string( $field ) ) {
143
+    if (!is_string($field)) {
144 144
         return false;
145 145
     }
146 146
 
147
-    switch( strtolower( $field ) ) {
147
+    switch (strtolower($field)) {
148 148
 
149 149
         case 'code':
150 150
             $meta_query     = array();
@@ -154,32 +154,32 @@  discard block
 block discarded – undo
154 154
                 'compare' => '='
155 155
             );
156 156
             
157
-            $discount = wpinv_get_discounts( array(
157
+            $discount = wpinv_get_discounts(array(
158 158
                 'posts_per_page' => 1,
159 159
                 'post_status'    => 'any',
160 160
                 'meta_query'     => $meta_query,
161
-            ) );
161
+            ));
162 162
             
163
-            if( $discount ) {
163
+            if ($discount) {
164 164
                 $discount = $discount[0];
165 165
             }
166 166
 
167 167
             break;
168 168
 
169 169
         case 'id':
170
-            $discount = wpinv_get_discount( $value );
170
+            $discount = wpinv_get_discount($value);
171 171
 
172 172
             break;
173 173
 
174 174
         case 'name':
175
-            $discount = get_posts( array(
175
+            $discount = get_posts(array(
176 176
                 'post_type'      => 'wpi_discount',
177 177
                 'name'           => $value,
178 178
                 'posts_per_page' => 1,
179 179
                 'post_status'    => 'any'
180
-            ) );
180
+            ));
181 181
 
182
-            if( $discount ) {
182
+            if ($discount) {
183 183
                 $discount = $discount[0];
184 184
             }
185 185
 
@@ -189,96 +189,96 @@  discard block
 block discarded – undo
189 189
             return false;
190 190
     }
191 191
 
192
-    if( ! empty( $discount ) ) {
192
+    if (!empty($discount)) {
193 193
         return $discount;
194 194
     }
195 195
 
196 196
     return false;
197 197
 }
198 198
 
199
-function wpinv_store_discount( $post_id, $data, $post, $update = false ) {
199
+function wpinv_store_discount($post_id, $data, $post, $update = false) {
200 200
     $meta = array(
201
-        'code'              => isset( $data['code'] )             ? sanitize_text_field( $data['code'] )              : '',
202
-        'type'              => isset( $data['type'] )             ? sanitize_text_field( $data['type'] )              : 'percent',
203
-        'amount'            => isset( $data['amount'] )           ? wpinv_sanitize_amount( $data['amount'] )          : '',
204
-        'start'             => isset( $data['start'] )            ? sanitize_text_field( $data['start'] )             : '',
205
-        'expiration'        => isset( $data['expiration'] )       ? sanitize_text_field( $data['expiration'] )        : '',
206
-        'min_total'         => isset( $data['min_total'] )        ? wpinv_sanitize_amount( $data['min_total'] )       : '',
207
-        'max_total'         => isset( $data['max_total'] )        ? wpinv_sanitize_amount( $data['max_total'] )       : '',
208
-        'max_uses'          => isset( $data['max_uses'] )         ? absint( $data['max_uses'] )                       : '',
209
-        'items'             => isset( $data['items'] )            ? $data['items']                                    : array(),
210
-        'excluded_items'    => isset( $data['excluded_items'] )   ? $data['excluded_items']                           : array(),
211
-        'is_recurring'      => isset( $data['recurring'] )        ? (bool)$data['recurring']                          : false,
212
-        'is_single_use'     => isset( $data['single_use'] )       ? (bool)$data['single_use']                         : false,
213
-        'uses'              => isset( $data['uses'] )             ? (int)$data['uses']                                : false,
201
+        'code'              => isset($data['code']) ? sanitize_text_field($data['code']) : '',
202
+        'type'              => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent',
203
+        'amount'            => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '',
204
+        'start'             => isset($data['start']) ? sanitize_text_field($data['start']) : '',
205
+        'expiration'        => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '',
206
+        'min_total'         => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '',
207
+        'max_total'         => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '',
208
+        'max_uses'          => isset($data['max_uses']) ? absint($data['max_uses']) : '',
209
+        'items'             => isset($data['items']) ? $data['items'] : array(),
210
+        'excluded_items'    => isset($data['excluded_items']) ? $data['excluded_items'] : array(),
211
+        'is_recurring'      => isset($data['recurring']) ? (bool)$data['recurring'] : false,
212
+        'is_single_use'     => isset($data['single_use']) ? (bool)$data['single_use'] : false,
213
+        'uses'              => isset($data['uses']) ? (int)$data['uses'] : false,
214 214
     );
215 215
 
216
-    if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) {
216
+    if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) {
217 217
         $meta['amount'] = 100;
218 218
     }
219 219
 
220
-    if ( !empty( $meta['start'] ) ) {
221
-        $meta['start']      = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) );
220
+    if (!empty($meta['start'])) {
221
+        $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start']));
222 222
     }
223 223
 
224
-    if ( !empty( $meta['expiration'] ) ) {
225
-        $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) );
224
+    if (!empty($meta['expiration'])) {
225
+        $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration']));
226 226
 
227
-        if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) {
227
+        if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) {
228 228
             $meta['expiration'] = $meta['start'];
229 229
         }
230 230
     }
231 231
     
232
-    if ( $meta['uses'] === false ) {
233
-        unset( $meta['uses'] );
232
+    if ($meta['uses'] === false) {
233
+        unset($meta['uses']);
234 234
     }
235 235
     
236
-    if ( ! empty( $meta['items'] ) ) {
237
-        foreach ( $meta['items'] as $key => $item ) {
238
-            if ( 0 === intval( $item ) ) {
239
-                unset( $meta['items'][ $key ] );
236
+    if (!empty($meta['items'])) {
237
+        foreach ($meta['items'] as $key => $item) {
238
+            if (0 === intval($item)) {
239
+                unset($meta['items'][$key]);
240 240
             }
241 241
         }
242 242
     }
243 243
     
244
-    if ( ! empty( $meta['excluded_items'] ) ) {
245
-        foreach ( $meta['excluded_items'] as $key => $item ) {
246
-            if ( 0 === intval( $item ) ) {
247
-                unset( $meta['excluded_items'][ $key ] );
244
+    if (!empty($meta['excluded_items'])) {
245
+        foreach ($meta['excluded_items'] as $key => $item) {
246
+            if (0 === intval($item)) {
247
+                unset($meta['excluded_items'][$key]);
248 248
             }
249 249
         }
250 250
     }
251 251
     
252
-    $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post );
252
+    $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post);
253 253
     
254
-    do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post );
254
+    do_action('wpinv_pre_update_discount', $meta, $post_id, $post);
255 255
     
256
-    foreach( $meta as $key => $value ) {
257
-        update_post_meta( $post_id, '_wpi_discount_' . $key, $value );
256
+    foreach ($meta as $key => $value) {
257
+        update_post_meta($post_id, '_wpi_discount_' . $key, $value);
258 258
     }
259 259
     
260
-    do_action( 'wpinv_post_update_discount', $meta, $post_id, $post );
260
+    do_action('wpinv_post_update_discount', $meta, $post_id, $post);
261 261
     
262 262
     return $post_id;
263 263
 }
264 264
 
265
-function wpinv_remove_discount( $discount_id = 0 ) {
266
-    do_action( 'wpinv_pre_delete_discount', $discount_id );
265
+function wpinv_remove_discount($discount_id = 0) {
266
+    do_action('wpinv_pre_delete_discount', $discount_id);
267 267
 
268
-    wp_delete_post( $discount_id, true );
268
+    wp_delete_post($discount_id, true);
269 269
 
270
-    do_action( 'wpinv_post_delete_discount', $discount_id );
270
+    do_action('wpinv_post_delete_discount', $discount_id);
271 271
 }
272 272
 
273
-function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) {
274
-    $discount = wpinv_get_discount(  $code_id );
273
+function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') {
274
+    $discount = wpinv_get_discount($code_id);
275 275
 
276
-    if ( $discount ) {
277
-        do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status );
276
+    if ($discount) {
277
+        do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status);
278 278
 
279
-        wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) );
279
+        wp_update_post(array('ID' => $code_id, 'post_status' => $new_status));
280 280
 
281
-        do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status );
281
+        do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status);
282 282
 
283 283
         return true;
284 284
     }
@@ -286,173 +286,173 @@  discard block
 block discarded – undo
286 286
     return false;
287 287
 }
288 288
 
289
-function wpinv_discount_exists( $code_id ) {
290
-    if ( wpinv_get_discount(  $code_id ) ) {
289
+function wpinv_discount_exists($code_id) {
290
+    if (wpinv_get_discount($code_id)) {
291 291
         return true;
292 292
     }
293 293
 
294 294
     return false;
295 295
 }
296 296
 
297
-function wpinv_is_discount_active( $code_id = null ) {
298
-    $discount = wpinv_get_discount(  $code_id );
297
+function wpinv_is_discount_active($code_id = null) {
298
+    $discount = wpinv_get_discount($code_id);
299 299
     $return   = false;
300 300
 
301
-    if ( $discount ) {
302
-        if ( wpinv_is_discount_expired( $code_id ) ) {
303
-            if( defined( 'DOING_AJAX' ) ) {
304
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) );
301
+    if ($discount) {
302
+        if (wpinv_is_discount_expired($code_id)) {
303
+            if (defined('DOING_AJAX')) {
304
+                wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing'));
305 305
             }
306
-        } elseif ( $discount->post_status == 'publish' ) {
306
+        } elseif ($discount->post_status == 'publish') {
307 307
             $return = true;
308 308
         } else {
309
-            if( defined( 'DOING_AJAX' ) ) {
310
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) );
309
+            if (defined('DOING_AJAX')) {
310
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing'));
311 311
             }
312 312
         }
313 313
     }
314 314
 
315
-    return apply_filters( 'wpinv_is_discount_active', $return, $code_id );
315
+    return apply_filters('wpinv_is_discount_active', $return, $code_id);
316 316
 }
317 317
 
318
-function wpinv_get_discount_code( $code_id = null ) {
319
-    $code = get_post_meta( $code_id, '_wpi_discount_code', true );
318
+function wpinv_get_discount_code($code_id = null) {
319
+    $code = get_post_meta($code_id, '_wpi_discount_code', true);
320 320
 
321
-    return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
321
+    return apply_filters('wpinv_get_discount_code', $code, $code_id);
322 322
 }
323 323
 
324
-function wpinv_get_discount_start_date( $code_id = null ) {
325
-    $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
324
+function wpinv_get_discount_start_date($code_id = null) {
325
+    $start_date = get_post_meta($code_id, '_wpi_discount_start', true);
326 326
 
327
-    return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
327
+    return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id);
328 328
 }
329 329
 
330
-function wpinv_get_discount_expiration( $code_id = null ) {
331
-    $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
330
+function wpinv_get_discount_expiration($code_id = null) {
331
+    $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true);
332 332
 
333
-    return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id );
333
+    return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id);
334 334
 }
335 335
 
336
-function wpinv_get_discount_max_uses( $code_id = null ) {
337
-    $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true );
336
+function wpinv_get_discount_max_uses($code_id = null) {
337
+    $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true);
338 338
 
339
-    return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id );
339
+    return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id);
340 340
 }
341 341
 
342
-function wpinv_get_discount_uses( $code_id = null ) {
343
-    $uses = get_post_meta( $code_id, '_wpi_discount_uses', true );
342
+function wpinv_get_discount_uses($code_id = null) {
343
+    $uses = get_post_meta($code_id, '_wpi_discount_uses', true);
344 344
 
345
-    return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id );
345
+    return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id);
346 346
 }
347 347
 
348
-function wpinv_get_discount_min_total( $code_id = null ) {
349
-    $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true );
348
+function wpinv_get_discount_min_total($code_id = null) {
349
+    $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true);
350 350
 
351
-    return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id );
351
+    return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id);
352 352
 }
353 353
 
354
-function wpinv_get_discount_max_total( $code_id = null ) {
355
-    $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true );
354
+function wpinv_get_discount_max_total($code_id = null) {
355
+    $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true);
356 356
 
357
-    return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id );
357
+    return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id);
358 358
 }
359 359
 
360
-function wpinv_get_discount_amount( $code_id = null ) {
361
-    $amount = get_post_meta( $code_id, '_wpi_discount_amount', true );
360
+function wpinv_get_discount_amount($code_id = null) {
361
+    $amount = get_post_meta($code_id, '_wpi_discount_amount', true);
362 362
 
363
-    return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id );
363
+    return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id);
364 364
 }
365 365
 
366
-function wpinv_get_discount_type( $code_id = null, $name = false ) {
367
-    $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) );
366
+function wpinv_get_discount_type($code_id = null, $name = false) {
367
+    $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true));
368 368
     
369
-    if ( $name ) {
370
-        $name = wpinv_get_discount_type_name( $type );
369
+    if ($name) {
370
+        $name = wpinv_get_discount_type_name($type);
371 371
         
372
-        return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id );
372
+        return apply_filters('wpinv_get_discount_type_name', $name, $code_id);
373 373
     }
374 374
 
375
-    return apply_filters( 'wpinv_get_discount_type', $type, $code_id );
375
+    return apply_filters('wpinv_get_discount_type', $type, $code_id);
376 376
 }
377 377
 
378
-function wpinv_discount_status( $status ) {
379
-    switch( $status ){
378
+function wpinv_discount_status($status) {
379
+    switch ($status) {
380 380
         case 'expired' :
381
-            $name = __( 'Expired', 'invoicing' );
381
+            $name = __('Expired', 'invoicing');
382 382
             break;
383 383
         case 'publish' :
384 384
         case 'active' :
385
-            $name = __( 'Active', 'invoicing' );
385
+            $name = __('Active', 'invoicing');
386 386
             break;
387 387
         default :
388
-            $name = __( 'Inactive', 'invoicing' );
388
+            $name = __('Inactive', 'invoicing');
389 389
             break;
390 390
     }
391 391
     return $name;
392 392
 }
393 393
 
394
-function wpinv_get_discount_excluded_items( $code_id = null ) {
395
-    $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true );
394
+function wpinv_get_discount_excluded_items($code_id = null) {
395
+    $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true);
396 396
 
397
-    if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) {
397
+    if (empty($excluded_items) || !is_array($excluded_items)) {
398 398
         $excluded_items = array();
399 399
     }
400 400
 
401
-    return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id );
401
+    return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id);
402 402
 }
403 403
 
404
-function wpinv_get_discount_item_reqs( $code_id = null ) {
405
-    $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true );
404
+function wpinv_get_discount_item_reqs($code_id = null) {
405
+    $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true);
406 406
 
407
-    if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) {
407
+    if (empty($item_reqs) || !is_array($item_reqs)) {
408 408
         $item_reqs = array();
409 409
     }
410 410
 
411
-    return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id );
411
+    return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id);
412 412
 }
413 413
 
414
-function wpinv_get_discount_item_condition( $code_id = 0 ) {
415
-    return get_post_meta( $code_id, '_wpi_discount_item_condition', true );
414
+function wpinv_get_discount_item_condition($code_id = 0) {
415
+    return get_post_meta($code_id, '_wpi_discount_item_condition', true);
416 416
 }
417 417
 
418
-function wpinv_is_discount_not_global( $code_id = 0 ) {
419
-    return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true );
418
+function wpinv_is_discount_not_global($code_id = 0) {
419
+    return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true);
420 420
 }
421 421
 
422
-function wpinv_is_discount_expired( $code_id = null ) {
423
-    $discount = wpinv_get_discount(  $code_id );
422
+function wpinv_is_discount_expired($code_id = null) {
423
+    $discount = wpinv_get_discount($code_id);
424 424
     $return   = false;
425 425
 
426
-    if ( $discount ) {
427
-        $expiration = wpinv_get_discount_expiration( $code_id );
428
-        if ( $expiration ) {
429
-            $expiration = strtotime( $expiration );
430
-            if ( $expiration < current_time( 'timestamp' ) ) {
426
+    if ($discount) {
427
+        $expiration = wpinv_get_discount_expiration($code_id);
428
+        if ($expiration) {
429
+            $expiration = strtotime($expiration);
430
+            if ($expiration < current_time('timestamp')) {
431 431
                 // Discount is expired
432
-                wpinv_update_discount_status( $code_id, 'pending' );
432
+                wpinv_update_discount_status($code_id, 'pending');
433 433
                 $return = true;
434 434
             }
435 435
         }
436 436
     }
437 437
 
438
-    return apply_filters( 'wpinv_is_discount_expired', $return, $code_id );
438
+    return apply_filters('wpinv_is_discount_expired', $return, $code_id);
439 439
 }
440 440
 
441
-function wpinv_is_discount_started( $code_id = null ) {
442
-    $discount = wpinv_get_discount(  $code_id );
441
+function wpinv_is_discount_started($code_id = null) {
442
+    $discount = wpinv_get_discount($code_id);
443 443
     $return   = false;
444 444
 
445
-    if ( $discount ) {
446
-        $start_date = wpinv_get_discount_start_date( $code_id );
445
+    if ($discount) {
446
+        $start_date = wpinv_get_discount_start_date($code_id);
447 447
 
448
-        if ( $start_date ) {
449
-            $start_date = strtotime( $start_date );
448
+        if ($start_date) {
449
+            $start_date = strtotime($start_date);
450 450
 
451
-            if ( $start_date < current_time( 'timestamp' ) ) {
451
+            if ($start_date < current_time('timestamp')) {
452 452
                 // Discount has past the start date
453 453
                 $return = true;
454 454
             } else {
455
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
455
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
456 456
             }
457 457
         } else {
458 458
             // No start date for this discount, so has to be true
@@ -460,159 +460,159 @@  discard block
 block discarded – undo
460 460
         }
461 461
     }
462 462
 
463
-    return apply_filters( 'wpinv_is_discount_started', $return, $code_id );
463
+    return apply_filters('wpinv_is_discount_started', $return, $code_id);
464 464
 }
465 465
 
466
-function wpinv_check_discount_dates( $code_id = null ) {
467
-    $discount = wpinv_get_discount(  $code_id );
466
+function wpinv_check_discount_dates($code_id = null) {
467
+    $discount = wpinv_get_discount($code_id);
468 468
     $return   = false;
469 469
 
470
-    if ( $discount ) {
471
-        $start_date = wpinv_get_discount_start_date( $code_id );
470
+    if ($discount) {
471
+        $start_date = wpinv_get_discount_start_date($code_id);
472 472
 
473
-        if ( $start_date ) {
474
-            $start_date = strtotime( $start_date );
473
+        if ($start_date) {
474
+            $start_date = strtotime($start_date);
475 475
 
476
-            if ( $start_date < current_time( 'timestamp' ) ) {
476
+            if ($start_date < current_time('timestamp')) {
477 477
                 // Discount has past the start date
478 478
                 $return = true;
479 479
             } else {
480
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
480
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
481 481
             }
482 482
         } else {
483 483
             // No start date for this discount, so has to be true
484 484
             $return = true;
485 485
         }
486 486
         
487
-        if ( $return ) {
488
-            $expiration = wpinv_get_discount_expiration( $code_id );
487
+        if ($return) {
488
+            $expiration = wpinv_get_discount_expiration($code_id);
489 489
             
490
-            if ( $expiration ) {
491
-                $expiration = strtotime( $expiration );
492
-                if ( $expiration < current_time( 'timestamp' ) ) {
490
+            if ($expiration) {
491
+                $expiration = strtotime($expiration);
492
+                if ($expiration < current_time('timestamp')) {
493 493
                     // Discount is expired
494
-                    wpinv_update_discount_status( $code_id, 'pending' );
494
+                    wpinv_update_discount_status($code_id, 'pending');
495 495
                     $return = true;
496 496
                 }
497 497
             }
498 498
         }
499 499
     }
500 500
     
501
-    return apply_filters( 'wpinv_check_discount_dates', $return, $code_id );
501
+    return apply_filters('wpinv_check_discount_dates', $return, $code_id);
502 502
 }
503 503
 
504
-function wpinv_is_discount_maxed_out( $code_id = null ) {
505
-    $discount = wpinv_get_discount(  $code_id );
504
+function wpinv_is_discount_maxed_out($code_id = null) {
505
+    $discount = wpinv_get_discount($code_id);
506 506
     $return   = false;
507 507
 
508
-    if ( $discount ) {
509
-        $uses = wpinv_get_discount_uses( $code_id );
508
+    if ($discount) {
509
+        $uses = wpinv_get_discount_uses($code_id);
510 510
         // Large number that will never be reached
511
-        $max_uses = wpinv_get_discount_max_uses( $code_id );
511
+        $max_uses = wpinv_get_discount_max_uses($code_id);
512 512
         // Should never be greater than, but just in case
513
-        if ( $uses >= $max_uses && ! empty( $max_uses ) ) {
513
+        if ($uses >= $max_uses && !empty($max_uses)) {
514 514
             // Discount is maxed out
515
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) );
515
+            wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing'));
516 516
             $return = true;
517 517
         }
518 518
     }
519 519
 
520
-    return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id );
520
+    return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id);
521 521
 }
522 522
 
523
-function wpinv_discount_is_min_met( $code_id = null ) {
524
-    $discount = wpinv_get_discount( $code_id );
523
+function wpinv_discount_is_min_met($code_id = null) {
524
+    $discount = wpinv_get_discount($code_id);
525 525
     $return   = false;
526 526
 
527
-    if ( $discount ) {
528
-        $min         = (float)wpinv_get_discount_min_total( $code_id );
529
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
527
+    if ($discount) {
528
+        $min         = (float)wpinv_get_discount_min_total($code_id);
529
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
530 530
 
531
-        if ( !$min > 0 || $cart_amount >= $min ) {
531
+        if (!$min > 0 || $cart_amount >= $min) {
532 532
             // Minimum has been met
533 533
             $return = true;
534 534
         } else {
535
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) );
535
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min))));
536 536
         }
537 537
     }
538 538
 
539
-    return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id );
539
+    return apply_filters('wpinv_is_discount_min_met', $return, $code_id);
540 540
 }
541 541
 
542
-function wpinv_discount_is_max_met( $code_id = null ) {
543
-    $discount = wpinv_get_discount( $code_id );
542
+function wpinv_discount_is_max_met($code_id = null) {
543
+    $discount = wpinv_get_discount($code_id);
544 544
     $return   = false;
545 545
 
546
-    if ( $discount ) {
547
-        $max         = (float)wpinv_get_discount_max_total( $code_id );
548
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
546
+    if ($discount) {
547
+        $max         = (float)wpinv_get_discount_max_total($code_id);
548
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
549 549
 
550
-        if ( !$max > 0 || $cart_amount <= $max ) {
550
+        if (!$max > 0 || $cart_amount <= $max) {
551 551
             // Minimum has been met
552 552
             $return = true;
553 553
         } else {
554
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) );
554
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max))));
555 555
         }
556 556
     }
557 557
 
558
-    return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id );
558
+    return apply_filters('wpinv_is_discount_max_met', $return, $code_id);
559 559
 }
560 560
 
561
-function wpinv_discount_is_single_use( $code_id = 0 ) {
562
-    $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true );
563
-    return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id );
561
+function wpinv_discount_is_single_use($code_id = 0) {
562
+    $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true);
563
+    return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id);
564 564
 }
565 565
 
566
-function wpinv_discount_is_recurring( $code_id = 0, $code = false ) {
567
-    if ( $code ) {
568
-        $discount = wpinv_get_discount_by_code( $code_id );
566
+function wpinv_discount_is_recurring($code_id = 0, $code = false) {
567
+    if ($code) {
568
+        $discount = wpinv_get_discount_by_code($code_id);
569 569
         
570
-        if ( !empty( $discount ) ) {
570
+        if (!empty($discount)) {
571 571
             $code_id = $discount->ID;
572 572
         }
573 573
     }
574 574
     
575
-    $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true );
575
+    $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true);
576 576
     
577
-    return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code );
577
+    return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code);
578 578
 }
579 579
 
580
-function wpinv_discount_item_reqs_met( $code_id = null ) {
581
-    $item_reqs    = wpinv_get_discount_item_reqs( $code_id );
582
-    $condition    = wpinv_get_discount_item_condition( $code_id );
583
-    $excluded_ps  = wpinv_get_discount_excluded_items( $code_id );
580
+function wpinv_discount_item_reqs_met($code_id = null) {
581
+    $item_reqs    = wpinv_get_discount_item_reqs($code_id);
582
+    $condition    = wpinv_get_discount_item_condition($code_id);
583
+    $excluded_ps  = wpinv_get_discount_excluded_items($code_id);
584 584
     $cart_items   = wpinv_get_cart_contents();
585
-    $cart_ids     = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null;
585
+    $cart_ids     = $cart_items ? wp_list_pluck($cart_items, 'id') : null;
586 586
     $ret          = false;
587 587
 
588
-    if ( empty( $item_reqs ) && empty( $excluded_ps ) ) {
588
+    if (empty($item_reqs) && empty($excluded_ps)) {
589 589
         $ret = true;
590 590
     }
591 591
 
592 592
     // Normalize our data for item requirements, exclusions and cart data
593 593
     // First absint the items, then sort, and reset the array keys
594
-    $item_reqs = array_map( 'absint', $item_reqs );
595
-    asort( $item_reqs );
596
-    $item_reqs = array_values( $item_reqs );
594
+    $item_reqs = array_map('absint', $item_reqs);
595
+    asort($item_reqs);
596
+    $item_reqs = array_values($item_reqs);
597 597
 
598
-    $excluded_ps  = array_map( 'absint', $excluded_ps );
599
-    asort( $excluded_ps );
600
-    $excluded_ps  = array_values( $excluded_ps );
598
+    $excluded_ps  = array_map('absint', $excluded_ps);
599
+    asort($excluded_ps);
600
+    $excluded_ps  = array_values($excluded_ps);
601 601
 
602
-    $cart_ids     = array_map( 'absint', $cart_ids );
603
-    asort( $cart_ids );
604
-    $cart_ids     = array_values( $cart_ids );
602
+    $cart_ids     = array_map('absint', $cart_ids);
603
+    asort($cart_ids);
604
+    $cart_ids     = array_values($cart_ids);
605 605
 
606 606
     // Ensure we have requirements before proceeding
607
-    if ( !$ret && ! empty( $item_reqs ) ) {
608
-        switch( $condition ) {
607
+    if (!$ret && !empty($item_reqs)) {
608
+        switch ($condition) {
609 609
             case 'all' :
610 610
                 // Default back to true
611 611
                 $ret = true;
612 612
 
613
-                foreach ( $item_reqs as $item_id ) {
614
-                    if ( !wpinv_item_in_cart( $item_id ) ) {
615
-                        wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
613
+                foreach ($item_reqs as $item_id) {
614
+                    if (!wpinv_item_in_cart($item_id)) {
615
+                        wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
616 616
                         $ret = false;
617 617
                         break;
618 618
                     }
@@ -621,15 +621,15 @@  discard block
 block discarded – undo
621 621
                 break;
622 622
 
623 623
             default : // Any
624
-                foreach ( $item_reqs as $item_id ) {
625
-                    if ( wpinv_item_in_cart( $item_id ) ) {
624
+                foreach ($item_reqs as $item_id) {
625
+                    if (wpinv_item_in_cart($item_id)) {
626 626
                         $ret = true;
627 627
                         break;
628 628
                     }
629 629
                 }
630 630
 
631
-                if( ! $ret ) {
632
-                    wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
631
+                if (!$ret) {
632
+                    wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
633 633
                 }
634 634
 
635 635
                 break;
@@ -638,70 +638,70 @@  discard block
 block discarded – undo
638 638
         $ret = true;
639 639
     }
640 640
 
641
-    if( ! empty( $excluded_ps ) ) {
641
+    if (!empty($excluded_ps)) {
642 642
         // Check that there are items other than excluded ones in the cart
643
-        if( $cart_ids == $excluded_ps ) {
644
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) );
643
+        if ($cart_ids == $excluded_ps) {
644
+            wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing'));
645 645
             $ret = false;
646 646
         }
647 647
     }
648 648
 
649
-    return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition );
649
+    return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition);
650 650
 }
651 651
 
652
-function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) {
652
+function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) {
653 653
     global $wpi_checkout_id;
654 654
     
655 655
     $return = false;
656 656
 
657
-    if ( empty( $code_id ) ) {
658
-        $code_id = wpinv_get_discount_id_by_code( $code );
657
+    if (empty($code_id)) {
658
+        $code_id = wpinv_get_discount_id_by_code($code);
659 659
         
660
-        if( empty( $code_id ) ) {
660
+        if (empty($code_id)) {
661 661
             return false; // No discount was found
662 662
         }
663 663
     }
664 664
 
665
-    if ( wpinv_discount_is_single_use( $code_id ) ) {
665
+    if (wpinv_discount_is_single_use($code_id)) {
666 666
         $payments = array();
667 667
 
668 668
         $user_id = 0;
669
-        if ( is_int( $user ) ) {
670
-            $user_id = absint( $user );
671
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
669
+        if (is_int($user)) {
670
+            $user_id = absint($user);
671
+        } else if (is_email($user) && $user_data = get_user_by('email', $user)) {
672 672
             $user_id = $user_data->ID;
673
-        } else if ( $user_data = get_user_by( 'login', $user ) ) {
673
+        } else if ($user_data = get_user_by('login', $user)) {
674 674
             $user_id = $user_data->ID;
675
-        } else if ( absint( $user ) > 0 ) {
676
-            $user_id = absint( $user );
675
+        } else if (absint($user) > 0) {
676
+            $user_id = absint($user);
677 677
         }
678 678
 
679
-        if ( !empty( $user_id ) ) {
680
-            $query    = array( 'user' => $user_id, 'limit' => false );
681
-            $payments = wpinv_get_invoices( $query ); // Get all payments with matching user id
679
+        if (!empty($user_id)) {
680
+            $query    = array('user' => $user_id, 'limit' => false);
681
+            $payments = wpinv_get_invoices($query); // Get all payments with matching user id
682 682
         }
683 683
 
684
-        if ( $payments ) {
685
-            foreach ( $payments as $payment ) {
684
+        if ($payments) {
685
+            foreach ($payments as $payment) {
686 686
                 // Don't count discount used for current invoice chekcout.
687
-                if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
687
+                if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) {
688 688
                     continue;
689 689
                 }
690 690
                 
691
-                if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
691
+                if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) {
692 692
                     continue;
693 693
                 }
694 694
 
695
-                $discounts = $payment->get_discounts( true );
696
-                if ( empty( $discounts ) ) {
695
+                $discounts = $payment->get_discounts(true);
696
+                if (empty($discounts)) {
697 697
                     continue;
698 698
                 }
699 699
 
700
-                $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts;
700
+                $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts;
701 701
 
702
-                if ( !empty( $discounts ) && is_array( $discounts ) ) {
703
-                    if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) {
704
-                        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) );
702
+                if (!empty($discounts) && is_array($discounts)) {
703
+                    if (in_array(strtolower($code), array_map('strtolower', $discounts))) {
704
+                        wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing'));
705 705
                         $return = true;
706 706
                         break;
707 707
                     }
@@ -710,61 +710,61 @@  discard block
 block discarded – undo
710 710
         }
711 711
     }
712 712
 
713
-    return apply_filters( 'wpinv_is_discount_used', $return, $code, $user );
713
+    return apply_filters('wpinv_is_discount_used', $return, $code, $user);
714 714
 }
715 715
 
716
-function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) {
716
+function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) {
717 717
     $return      = false;
718
-    $discount_id = wpinv_get_discount_id_by_code( $code );
719
-    $user        = trim( $user );
718
+    $discount_id = wpinv_get_discount_id_by_code($code);
719
+    $user        = trim($user);
720 720
 
721
-    if ( wpinv_get_cart_contents() ) {
722
-        if ( $discount_id ) {
721
+    if (wpinv_get_cart_contents()) {
722
+        if ($discount_id) {
723 723
             if (
724
-                wpinv_is_discount_active( $discount_id ) &&
725
-                wpinv_check_discount_dates( $discount_id ) &&
726
-                !wpinv_is_discount_maxed_out( $discount_id ) &&
727
-                !wpinv_is_discount_used( $code, $user, $discount_id ) &&
728
-                wpinv_discount_is_min_met( $discount_id ) &&
729
-                wpinv_discount_is_max_met( $discount_id ) &&
730
-                wpinv_discount_item_reqs_met( $discount_id )
724
+                wpinv_is_discount_active($discount_id) &&
725
+                wpinv_check_discount_dates($discount_id) &&
726
+                !wpinv_is_discount_maxed_out($discount_id) &&
727
+                !wpinv_is_discount_used($code, $user, $discount_id) &&
728
+                wpinv_discount_is_min_met($discount_id) &&
729
+                wpinv_discount_is_max_met($discount_id) &&
730
+                wpinv_discount_item_reqs_met($discount_id)
731 731
             ) {
732 732
                 $return = true;
733 733
             }
734
-        } elseif( $set_error ) {
735
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) );
734
+        } elseif ($set_error) {
735
+            wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing'));
736 736
         }
737 737
     }
738 738
 
739
-    return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user );
739
+    return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user);
740 740
 }
741 741
 
742
-function wpinv_get_discount_id_by_code( $code ) {
743
-    $discount = wpinv_get_discount_by_code( $code );
744
-    if( $discount ) {
742
+function wpinv_get_discount_id_by_code($code) {
743
+    $discount = wpinv_get_discount_by_code($code);
744
+    if ($discount) {
745 745
         return $discount->ID;
746 746
     }
747 747
     return false;
748 748
 }
749 749
 
750
-function wpinv_get_discounted_amount( $code, $base_price ) {
750
+function wpinv_get_discounted_amount($code, $base_price) {
751 751
     $amount      = $base_price;
752
-    $discount_id = wpinv_get_discount_id_by_code( $code );
752
+    $discount_id = wpinv_get_discount_id_by_code($code);
753 753
 
754
-    if( $discount_id ) {
755
-        $type        = wpinv_get_discount_type( $discount_id );
756
-        $rate        = wpinv_get_discount_amount( $discount_id );
754
+    if ($discount_id) {
755
+        $type        = wpinv_get_discount_type($discount_id);
756
+        $rate        = wpinv_get_discount_amount($discount_id);
757 757
 
758
-        if ( $type == 'flat' ) {
758
+        if ($type == 'flat') {
759 759
             // Set amount
760 760
             $amount = $base_price - $rate;
761
-            if ( $amount < 0 ) {
761
+            if ($amount < 0) {
762 762
                 $amount = 0;
763 763
             }
764 764
 
765 765
         } else {
766 766
             // Percentage discount
767
-            $amount = $base_price - ( $base_price * ( $rate / 100 ) );
767
+            $amount = $base_price - ($base_price * ($rate / 100));
768 768
         }
769 769
 
770 770
     } else {
@@ -773,108 +773,108 @@  discard block
 block discarded – undo
773 773
 
774 774
     }
775 775
 
776
-    return apply_filters( 'wpinv_discounted_amount', $amount );
776
+    return apply_filters('wpinv_discounted_amount', $amount);
777 777
 }
778 778
 
779
-function wpinv_increase_discount_usage( $code ) {
779
+function wpinv_increase_discount_usage($code) {
780 780
 
781
-    $id   = wpinv_get_discount_id_by_code( $code );
782
-    $uses = wpinv_get_discount_uses( $id );
781
+    $id   = wpinv_get_discount_id_by_code($code);
782
+    $uses = wpinv_get_discount_uses($id);
783 783
 
784
-    if ( $uses ) {
784
+    if ($uses) {
785 785
         $uses++;
786 786
     } else {
787 787
         $uses = 1;
788 788
     }
789 789
 
790
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
790
+    update_post_meta($id, '_wpi_discount_uses', $uses);
791 791
 
792
-    do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code );
792
+    do_action('wpinv_discount_increase_use_count', $uses, $id, $code);
793 793
 
794 794
     return $uses;
795 795
 
796 796
 }
797 797
 
798
-function wpinv_decrease_discount_usage( $code ) {
798
+function wpinv_decrease_discount_usage($code) {
799 799
 
800
-    $id   = wpinv_get_discount_id_by_code( $code );
801
-    $uses = wpinv_get_discount_uses( $id );
800
+    $id   = wpinv_get_discount_id_by_code($code);
801
+    $uses = wpinv_get_discount_uses($id);
802 802
 
803
-    if ( $uses ) {
803
+    if ($uses) {
804 804
         $uses--;
805 805
     }
806 806
 
807
-    if ( $uses < 0 ) {
807
+    if ($uses < 0) {
808 808
         $uses = 0;
809 809
     }
810 810
 
811
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
811
+    update_post_meta($id, '_wpi_discount_uses', $uses);
812 812
 
813
-    do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code );
813
+    do_action('wpinv_discount_decrease_use_count', $uses, $id, $code);
814 814
 
815 815
     return $uses;
816 816
 
817 817
 }
818 818
 
819
-function wpinv_format_discount_rate( $type, $amount ) {
820
-    if ( $type == 'flat' ) {
821
-        return wpinv_price( wpinv_format_amount( $amount ) );
819
+function wpinv_format_discount_rate($type, $amount) {
820
+    if ($type == 'flat') {
821
+        return wpinv_price(wpinv_format_amount($amount));
822 822
     } else {
823 823
         return $amount . '%';
824 824
     }
825 825
 }
826 826
 
827
-function wpinv_set_cart_discount( $code = '' ) {    
828
-    if ( wpinv_multiple_discounts_allowed() ) {
827
+function wpinv_set_cart_discount($code = '') {    
828
+    if (wpinv_multiple_discounts_allowed()) {
829 829
         // Get all active cart discounts
830 830
         $discounts = wpinv_get_cart_discounts();
831 831
     } else {
832 832
         $discounts = false; // Only one discount allowed per purchase, so override any existing
833 833
     }
834 834
 
835
-    if ( $discounts ) {
836
-        $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) );
837
-        if( false !== $key ) {
838
-            unset( $discounts[ $key ] ); // Can't set the same discount more than once
835
+    if ($discounts) {
836
+        $key = array_search(strtolower($code), array_map('strtolower', $discounts));
837
+        if (false !== $key) {
838
+            unset($discounts[$key]); // Can't set the same discount more than once
839 839
         }
840 840
         $discounts[] = $code;
841 841
     } else {
842 842
         $discounts = array();
843 843
         $discounts[] = $code;
844 844
     }
845
-    $discounts = array_values( $discounts );
845
+    $discounts = array_values($discounts);
846 846
     
847 847
     $data = wpinv_get_checkout_session();
848
-    if ( empty( $data ) ) {
848
+    if (empty($data)) {
849 849
         $data = array();
850 850
     } else {
851
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
852
-            $payment_meta['user_info']['discount']  = implode( ',', $discounts );
853
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
851
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
852
+            $payment_meta['user_info']['discount'] = implode(',', $discounts);
853
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
854 854
         }
855 855
     }
856 856
     $data['cart_discounts'] = $discounts;
857 857
     
858
-    wpinv_set_checkout_session( $data );
858
+    wpinv_set_checkout_session($data);
859 859
     
860 860
     return $discounts;
861 861
 }
862 862
 
863
-function wpinv_unset_cart_discount( $code = '' ) {    
863
+function wpinv_unset_cart_discount($code = '') {    
864 864
     $discounts = wpinv_get_cart_discounts();
865 865
 
866
-    if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) {
867
-        $key = array_search( $code, $discounts );
868
-        unset( $discounts[ $key ] );
866
+    if ($code && !empty($discounts) && in_array($code, $discounts)) {
867
+        $key = array_search($code, $discounts);
868
+        unset($discounts[$key]);
869 869
             
870 870
         $data = wpinv_get_checkout_session();
871 871
         $data['cart_discounts'] = $discounts;
872
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
873
-            $payment_meta['user_info']['discount']  = !empty( $discounts ) ? implode( ',', $discounts ) : '';
874
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
872
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
873
+            $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : '';
874
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
875 875
         }
876 876
         
877
-        wpinv_set_checkout_session( $data );
877
+        wpinv_set_checkout_session($data);
878 878
     }
879 879
 
880 880
     return $discounts;
@@ -883,27 +883,27 @@  discard block
 block discarded – undo
883 883
 function wpinv_unset_all_cart_discounts() {
884 884
     $data = wpinv_get_checkout_session();
885 885
     
886
-    if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
887
-        unset( $data['cart_discounts'] );
886
+    if (!empty($data) && isset($data['cart_discounts'])) {
887
+        unset($data['cart_discounts']);
888 888
         
889
-         wpinv_set_checkout_session( $data );
889
+         wpinv_set_checkout_session($data);
890 890
          return true;
891 891
     }
892 892
     
893 893
     return false;
894 894
 }
895 895
 
896
-function wpinv_get_cart_discounts( $items = array() ) {
896
+function wpinv_get_cart_discounts($items = array()) {
897 897
     $session = wpinv_get_checkout_session();
898 898
     
899
-    $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false;
899
+    $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false;
900 900
     return $discounts;
901 901
 }
902 902
 
903
-function wpinv_cart_has_discounts( $items = array() ) {
903
+function wpinv_cart_has_discounts($items = array()) {
904 904
     $ret = false;
905 905
 
906
-    if ( wpinv_get_cart_discounts( $items ) ) {
906
+    if (wpinv_get_cart_discounts($items)) {
907 907
         $ret = true;
908 908
     }
909 909
     
@@ -914,131 +914,131 @@  discard block
 block discarded – undo
914 914
     }
915 915
     */
916 916
 
917
-    return apply_filters( 'wpinv_cart_has_discounts', $ret );
917
+    return apply_filters('wpinv_cart_has_discounts', $ret);
918 918
 }
919 919
 
920
-function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) {
920
+function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) {
921 921
     $amount = 0.00;
922
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
922
+    $items  = !empty($items) ? $items : wpinv_get_cart_content_details();
923 923
 
924
-    if ( $items ) {
925
-        $discounts = wp_list_pluck( $items, 'discount' );
924
+    if ($items) {
925
+        $discounts = wp_list_pluck($items, 'discount');
926 926
 
927
-        if ( is_array( $discounts ) ) {
928
-            $discounts = array_map( 'floatval', $discounts );
929
-            $amount    = array_sum( $discounts );
927
+        if (is_array($discounts)) {
928
+            $discounts = array_map('floatval', $discounts);
929
+            $amount    = array_sum($discounts);
930 930
         }
931 931
     }
932 932
 
933
-    return apply_filters( 'wpinv_get_cart_discounted_amount', $amount );
933
+    return apply_filters('wpinv_get_cart_discounted_amount', $amount);
934 934
 }
935 935
 
936
-function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) {
937
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
936
+function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) {
937
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
938 938
     
939
-    if ( empty( $discount ) || empty( $items ) ) {
939
+    if (empty($discount) || empty($items)) {
940 940
         return 0;
941 941
     }
942 942
 
943 943
     $amount = 0;
944 944
     
945
-    foreach ( $items as $item ) {
946
-        $amount += wpinv_get_cart_item_discount_amount( $item, $discount );
945
+    foreach ($items as $item) {
946
+        $amount += wpinv_get_cart_item_discount_amount($item, $discount);
947 947
     }
948 948
     
949
-    $amount = wpinv_round_amount( $amount );
949
+    $amount = wpinv_round_amount($amount);
950 950
 
951 951
     return $amount;
952 952
 }
953 953
 
954
-function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) {
954
+function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) {
955 955
     global $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
956 956
     
957 957
     $amount = 0;
958 958
 
959
-    if ( empty( $item ) || empty( $item['id'] ) ) {
959
+    if (empty($item) || empty($item['id'])) {
960 960
         return $amount;
961 961
     }
962 962
 
963
-    if ( empty( $item['quantity'] ) ) {
963
+    if (empty($item['quantity'])) {
964 964
         return $amount;
965 965
     }
966 966
 
967
-    if ( empty( $item['options'] ) ) {
967
+    if (empty($item['options'])) {
968 968
         $item['options'] = array();
969 969
     }
970 970
 
971
-    $price            = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] );
971
+    $price            = wpinv_get_cart_item_price($item['id'], $item, $item['options']);
972 972
     $discounted_price = $price;
973 973
 
974 974
     $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount;
975
-    if ( empty( $discounts ) ) {
975
+    if (empty($discounts)) {
976 976
         return $amount;
977 977
     }
978 978
 
979
-    if ( $discounts ) {
980
-        if ( is_array( $discounts ) ) {
981
-            $discounts = array_values( $discounts );
979
+    if ($discounts) {
980
+        if (is_array($discounts)) {
981
+            $discounts = array_values($discounts);
982 982
         } else {
983
-            $discounts = explode( ',', $discounts );
983
+            $discounts = explode(',', $discounts);
984 984
         }
985 985
     }
986 986
 
987
-    if( $discounts ) {
988
-        foreach ( $discounts as $discount ) {
989
-            $code_id = wpinv_get_discount_id_by_code( $discount );
987
+    if ($discounts) {
988
+        foreach ($discounts as $discount) {
989
+            $code_id = wpinv_get_discount_id_by_code($discount);
990 990
 
991 991
             // Check discount exists
992
-            if( ! $code_id ) {
992
+            if (!$code_id) {
993 993
                 continue;
994 994
             }
995 995
 
996
-            $reqs           = wpinv_get_discount_item_reqs( $code_id );
997
-            $excluded_items = wpinv_get_discount_excluded_items( $code_id );
996
+            $reqs           = wpinv_get_discount_item_reqs($code_id);
997
+            $excluded_items = wpinv_get_discount_excluded_items($code_id);
998 998
 
999 999
             // Make sure requirements are set and that this discount shouldn't apply to the whole cart
1000
-            if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) {
1001
-                foreach ( $reqs as $item_id ) {
1002
-                    if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) {
1003
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1000
+            if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) {
1001
+                foreach ($reqs as $item_id) {
1002
+                    if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) {
1003
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1004 1004
                     }
1005 1005
                 }
1006 1006
             } else {
1007 1007
                 // This is a global cart discount
1008
-                if ( !in_array( $item['id'], $excluded_items ) ) {
1009
-                    if ( 'flat' === wpinv_get_discount_type( $code_id ) ) {
1008
+                if (!in_array($item['id'], $excluded_items)) {
1009
+                    if ('flat' === wpinv_get_discount_type($code_id)) {
1010 1010
                         $items_subtotal    = 0.00;
1011 1011
                         $cart_items        = wpinv_get_cart_contents();
1012 1012
                         
1013
-                        foreach ( $cart_items as $cart_item ) {
1014
-                            if ( ! in_array( $cart_item['id'], $excluded_items ) ) {
1015
-                                $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array();
1016
-                                $item_price      = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options );
1013
+                        foreach ($cart_items as $cart_item) {
1014
+                            if (!in_array($cart_item['id'], $excluded_items)) {
1015
+                                $options = !empty($cart_item['options']) ? $cart_item['options'] : array();
1016
+                                $item_price      = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options);
1017 1017
                                 $items_subtotal += $item_price * $cart_item['quantity'];
1018 1018
                             }
1019 1019
                         }
1020 1020
 
1021
-                        $subtotal_percent  = ( ( $price * $item['quantity'] ) / $items_subtotal );
1022
-                        $code_amount       = wpinv_get_discount_amount( $code_id );
1021
+                        $subtotal_percent  = (($price * $item['quantity']) / $items_subtotal);
1022
+                        $code_amount       = wpinv_get_discount_amount($code_id);
1023 1023
                         $discounted_amount = $code_amount * $subtotal_percent;
1024 1024
                         $discounted_price -= $discounted_amount;
1025 1025
 
1026
-                        $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() );
1026
+                        $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter());
1027 1027
 
1028
-                        if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) {
1028
+                        if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) {
1029 1029
                             $adjustment = $code_amount - $wpinv_flat_discount_total;
1030 1030
                             $discounted_price -= $adjustment;
1031 1031
                         }
1032 1032
                     } else {
1033
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1033
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1034 1034
                     }
1035 1035
                 }
1036 1036
             }
1037 1037
         }
1038 1038
 
1039
-        $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) );
1039
+        $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price));
1040 1040
 
1041
-        if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) {
1041
+        if ('flat' !== wpinv_get_discount_type($code_id)) {
1042 1042
             $amount = $amount * $item['quantity'];
1043 1043
         }
1044 1044
     }
@@ -1046,59 +1046,59 @@  discard block
 block discarded – undo
1046 1046
     return $amount;
1047 1047
 }
1048 1048
 
1049
-function wpinv_cart_discounts_html( $items = array() ) {
1050
-    echo wpinv_get_cart_discounts_html( $items );
1049
+function wpinv_cart_discounts_html($items = array()) {
1050
+    echo wpinv_get_cart_discounts_html($items);
1051 1051
 }
1052 1052
 
1053
-function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) {
1053
+function wpinv_get_cart_discounts_html($items = array(), $discounts = false) {
1054 1054
     global $wpi_cart_columns;
1055 1055
     
1056
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1056
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1057 1057
     
1058
-    if ( !$discounts ) {
1059
-        $discounts = wpinv_get_cart_discounts( $items );
1058
+    if (!$discounts) {
1059
+        $discounts = wpinv_get_cart_discounts($items);
1060 1060
     }
1061 1061
 
1062
-    if ( !$discounts ) {
1062
+    if (!$discounts) {
1063 1063
         return;
1064 1064
     }
1065 1065
     
1066
-    $discounts = is_array( $discounts ) ? $discounts : array( $discounts );
1066
+    $discounts = is_array($discounts) ? $discounts : array($discounts);
1067 1067
     
1068 1068
     $html = '';
1069 1069
 
1070
-    foreach ( $discounts as $discount ) {
1071
-        $discount_id    = wpinv_get_discount_id_by_code( $discount );
1072
-        $discount_value = wpinv_get_discount_amount( $discount_id );
1073
-        $rate           = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value );
1074
-        $amount         = wpinv_get_cart_items_discount_amount( $items, $discount );
1075
-        $remove_btn     = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1070
+    foreach ($discounts as $discount) {
1071
+        $discount_id    = wpinv_get_discount_id_by_code($discount);
1072
+        $discount_value = wpinv_get_discount_amount($discount_id);
1073
+        $rate           = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value);
1074
+        $amount         = wpinv_get_cart_items_discount_amount($items, $discount);
1075
+        $remove_btn     = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1076 1076
         
1077 1077
         $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">';
1078 1078
         ob_start();
1079
-        do_action( 'wpinv_checkout_table_discount_first', $items );
1079
+        do_action('wpinv_checkout_table_discount_first', $items);
1080 1080
         $html .= ob_get_clean();
1081
-        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>';
1081
+        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>';
1082 1082
         ob_start();
1083
-        do_action( 'wpinv_checkout_table_discount_last', $items );
1083
+        do_action('wpinv_checkout_table_discount_last', $items);
1084 1084
         $html .= ob_get_clean();
1085 1085
         $html .= '</tr>';
1086 1086
     }
1087 1087
 
1088
-    return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate );
1088
+    return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate);
1089 1089
 }
1090 1090
 
1091
-function wpinv_display_cart_discount( $formatted = false, $echo = false ) {
1091
+function wpinv_display_cart_discount($formatted = false, $echo = false) {
1092 1092
     $discounts = wpinv_get_cart_discounts();
1093 1093
 
1094
-    if ( empty( $discounts ) ) {
1094
+    if (empty($discounts)) {
1095 1095
         return false;
1096 1096
     }
1097 1097
 
1098
-    $discount_id  = wpinv_get_discount_id_by_code( $discounts[0] );
1099
-    $amount       = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) );
1098
+    $discount_id  = wpinv_get_discount_id_by_code($discounts[0]);
1099
+    $amount       = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id));
1100 1100
 
1101
-    if ( $echo ) {
1101
+    if ($echo) {
1102 1102
         echo $amount;
1103 1103
     }
1104 1104
 
@@ -1106,135 +1106,135 @@  discard block
 block discarded – undo
1106 1106
 }
1107 1107
 
1108 1108
 function wpinv_remove_cart_discount() {
1109
-    if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) {
1109
+    if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) {
1110 1110
         return;
1111 1111
     }
1112 1112
 
1113
-    do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) );
1113
+    do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id']));
1114 1114
 
1115
-    wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) );
1115
+    wpinv_unset_cart_discount(urldecode($_GET['discount_code']));
1116 1116
 
1117
-    do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) );
1117
+    do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id']));
1118 1118
 
1119
-    wp_redirect( wpinv_get_checkout_uri() ); wpinv_die();
1119
+    wp_redirect(wpinv_get_checkout_uri()); wpinv_die();
1120 1120
 }
1121
-add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' );
1121
+add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount');
1122 1122
 
1123
-function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) {
1123
+function wpinv_maybe_remove_cart_discount($cart_key = 0) {
1124 1124
     $discounts = wpinv_get_cart_discounts();
1125 1125
 
1126
-    if ( !$discounts ) {
1126
+    if (!$discounts) {
1127 1127
         return;
1128 1128
     }
1129 1129
 
1130
-    foreach ( $discounts as $discount ) {
1131
-        if ( !wpinv_is_discount_valid( $discount ) ) {
1132
-            wpinv_unset_cart_discount( $discount );
1130
+    foreach ($discounts as $discount) {
1131
+        if (!wpinv_is_discount_valid($discount)) {
1132
+            wpinv_unset_cart_discount($discount);
1133 1133
         }
1134 1134
     }
1135 1135
 }
1136
-add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' );
1136
+add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount');
1137 1137
 
1138 1138
 function wpinv_multiple_discounts_allowed() {
1139
-    $ret = wpinv_get_option( 'allow_multiple_discounts', false );
1140
-    return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret );
1139
+    $ret = wpinv_get_option('allow_multiple_discounts', false);
1140
+    return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret);
1141 1141
 }
1142 1142
 
1143 1143
 function wpinv_listen_for_cart_discount() {
1144 1144
     global $wpi_session;
1145 1145
     
1146
-    if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) {
1146
+    if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) {
1147 1147
         return;
1148 1148
     }
1149 1149
 
1150
-    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] );
1150
+    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']);
1151 1151
 
1152
-    $wpi_session->set( 'preset_discount', $code );
1152
+    $wpi_session->set('preset_discount', $code);
1153 1153
 }
1154 1154
 //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 );
1155 1155
 
1156 1156
 function wpinv_apply_preset_discount() {
1157 1157
     global $wpi_session;
1158 1158
     
1159
-    $code = $wpi_session->get( 'preset_discount' );
1159
+    $code = $wpi_session->get('preset_discount');
1160 1160
 
1161
-    if ( !$code ) {
1161
+    if (!$code) {
1162 1162
         return;
1163 1163
     }
1164 1164
 
1165
-    if ( !wpinv_is_discount_valid( $code, '', false ) ) {
1165
+    if (!wpinv_is_discount_valid($code, '', false)) {
1166 1166
         return;
1167 1167
     }
1168 1168
     
1169
-    $code = apply_filters( 'wpinv_apply_preset_discount', $code );
1169
+    $code = apply_filters('wpinv_apply_preset_discount', $code);
1170 1170
 
1171
-    wpinv_set_cart_discount( $code );
1171
+    wpinv_set_cart_discount($code);
1172 1172
 
1173
-    $wpi_session->set( 'preset_discount', null );
1173
+    $wpi_session->set('preset_discount', null);
1174 1174
 }
1175 1175
 //add_action( 'init', 'wpinv_apply_preset_discount', 999 );
1176 1176
 
1177
-function wpinv_get_discount_label( $code, $echo = true ) {
1178
-    $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1179
-    $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
1177
+function wpinv_get_discount_label($code, $echo = true) {
1178
+    $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : ''));
1179
+    $label = apply_filters('wpinv_get_discount_label', $label, $code);
1180 1180
 
1181
-    if ( $echo ) {
1181
+    if ($echo) {
1182 1182
         echo $label;
1183 1183
     } else {
1184 1184
         return $label;
1185 1185
     }
1186 1186
 }
1187 1187
 
1188
-function wpinv_cart_discount_label( $code, $rate, $echo = true ) {
1189
-    $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code );
1190
-    $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate );
1188
+function wpinv_cart_discount_label($code, $rate, $echo = true) {
1189
+    $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code);
1190
+    $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate);
1191 1191
 
1192
-    if ( $echo ) {
1192
+    if ($echo) {
1193 1193
         echo $label;
1194 1194
     } else {
1195 1195
         return $label;
1196 1196
     }
1197 1197
 }
1198 1198
 
1199
-function wpinv_check_delete_discount( $check, $post, $force_delete ) {
1200
-    if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) {
1199
+function wpinv_check_delete_discount($check, $post, $force_delete) {
1200
+    if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) {
1201 1201
         return true;
1202 1202
     }
1203 1203
     
1204 1204
     return $check;
1205 1205
 }
1206
-add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 );
1206
+add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3);
1207 1207
 
1208 1208
 function wpinv_checkout_form_validate_discounts() {
1209 1209
     global $wpi_checkout_id;
1210 1210
     
1211 1211
     $discounts = wpinv_get_cart_discounts();
1212 1212
     
1213
-    if ( !empty( $discounts ) ) {
1213
+    if (!empty($discounts)) {
1214 1214
         $invalid = false;
1215 1215
         
1216
-        foreach ( $discounts as $key => $code ) {
1217
-            if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) {
1216
+        foreach ($discounts as $key => $code) {
1217
+            if (!wpinv_is_discount_valid($code, (int)wpinv_get_user_id($wpi_checkout_id))) {
1218 1218
                 $invalid = true;
1219 1219
                 
1220
-                wpinv_unset_cart_discount( $code );
1220
+                wpinv_unset_cart_discount($code);
1221 1221
             }
1222 1222
         }
1223 1223
         
1224
-        if ( $invalid ) {
1224
+        if ($invalid) {
1225 1225
             $errors = wpinv_get_errors();
1226
-            $error  = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : '';
1227
-            $error  .= __( 'The discount has been removed from cart.', 'invoicing' );
1228
-            wpinv_set_error( 'wpinv-discount-error', $error );
1226
+            $error  = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : '';
1227
+            $error .= __('The discount has been removed from cart.', 'invoicing');
1228
+            wpinv_set_error('wpinv-discount-error', $error);
1229 1229
             
1230
-            wpinv_recalculate_tax( true );
1230
+            wpinv_recalculate_tax(true);
1231 1231
         }
1232 1232
     }
1233 1233
 }
1234
-add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 );
1234
+add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10);
1235 1235
 
1236 1236
 function wpinv_discount_amount() {
1237 1237
     $output = 0.00;
1238 1238
     
1239
-    return apply_filters( 'wpinv_discount_amount', $output );
1239
+    return apply_filters('wpinv_discount_amount', $output);
1240 1240
 }
1241 1241
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/manual.php 1 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/authorizenet.php 1 patch
Spacing   +241 added lines, -241 removed lines patch added patch discarded remove patch
@@ -1,60 +1,60 @@  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_filter( 'wpinv_authorizenet_support_subscription', '__return_true' );
5
+add_filter('wpinv_authorizenet_support_subscription', '__return_true');
6 6
 
7
-function wpinv_authorizenet_cc_form( $invoice_id ) {
8
-    $invoice = wpinv_get_invoice( $invoice_id );
9
-    $cc_owner = !empty( $invoice ) ? esc_attr( $invoice->get_user_full_name() ) : '';
7
+function wpinv_authorizenet_cc_form($invoice_id) {
8
+    $invoice = wpinv_get_invoice($invoice_id);
9
+    $cc_owner = !empty($invoice) ? esc_attr($invoice->get_user_full_name()) : '';
10 10
     ?>
11 11
     <div id="authorizenet_cc_form" class="form-horizontal wpi-cc-form panel panel-default">
12
-        <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Card Details', 'invoicing' ) ;?></h3></div>
12
+        <div class="panel-heading"><h3 class="panel-title"><?php _e('Card Details', 'invoicing'); ?></h3></div>
13 13
         <div class="panel-body">
14 14
             <div class="form-group required">
15
-              <label for="auth-input-cc-owner" class="col-sm-3 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label>
15
+              <label for="auth-input-cc-owner" class="col-sm-3 control-label"><?php _e('Card Owner', 'invoicing'); ?></label>
16 16
               <div class="col-sm-5">
17
-                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e( 'Card Owner', 'invoicing' ) ;?>" value="<?php echo $cc_owner;?>" name="authorizenet[cc_owner]">
17
+                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e('Card Owner', 'invoicing'); ?>" value="<?php echo $cc_owner; ?>" name="authorizenet[cc_owner]">
18 18
               </div>
19 19
             </div>
20 20
             <div class="form-group required">
21
-              <label for="auth-input-cc-number" class="col-sm-3 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label>
21
+              <label for="auth-input-cc-number" class="col-sm-3 control-label"><?php _e('Card Number', 'invoicing'); ?></label>
22 22
               <div class="col-sm-5">
23
-                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e( 'Card Number', 'invoicing' ) ;?>" value="" name="authorizenet[cc_number]">
23
+                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e('Card Number', 'invoicing'); ?>" value="" name="authorizenet[cc_number]">
24 24
               </div>
25 25
             </div>
26 26
             <div class="form-group required">
27
-              <label for="auth-input-cc-expire-date" class="col-sm-3 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label>
27
+              <label for="auth-input-cc-expire-date" class="col-sm-3 control-label"><?php _e('Card Expiry Date', 'invoicing'); ?></label>
28 28
               <div class="col-sm-2">
29 29
                 <select class="form-control" id="auth-input-cc-expire-date" name="authorizenet[cc_expire_month]">
30
-                    <?php for ( $i = 1; $i <= 12; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
31
-                    <option value="<?php echo $value;?>"><?php echo $value;?></option>
30
+                    <?php for ($i = 1; $i <= 12; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
31
+                    <option value="<?php echo $value; ?>"><?php echo $value; ?></option>
32 32
                     <?php } ?>
33 33
                 </select>
34 34
                </div>
35 35
                <div class="col-sm-3">
36 36
                 <select class="form-control" name="authorizenet[cc_expire_year]">
37
-                    <?php $year = date( 'Y' ); for ( $i = $year; $i <= ( $year + 10 ); $i++ ) { ?>
38
-                    <option value="<?php echo $i;?>"><?php echo $i;?></option>
37
+                    <?php $year = date('Y'); for ($i = $year; $i <= ($year + 10); $i++) { ?>
38
+                    <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
39 39
                     <?php } ?>
40 40
                 </select>
41 41
               </div>
42 42
             </div>
43 43
             <div class="form-group required">
44
-              <label for="auth-input-cc-cvv2" class="col-sm-3 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label>
44
+              <label for="auth-input-cc-cvv2" class="col-sm-3 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label>
45 45
               <div class="col-sm-5">
46
-                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e( 'Card Security Code (CVV2)', 'invoicing' ) ;?>" value="" name="authorizenet[cc_cvv2]"">
46
+                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e('Card Security Code (CVV2)', 'invoicing'); ?>" value="" name="authorizenet[cc_cvv2]"">
47 47
               </div>
48 48
             </div>
49 49
       </div>
50 50
     </div>
51 51
     <?php
52 52
 }
53
-add_action( 'wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1 );
53
+add_action('wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1);
54 54
 
55
-function wpinv_process_authorizenet_payment( $purchase_data ) {
56
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
57
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_process_authorizenet_payment($purchase_data) {
56
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
57
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
 
60 60
     // Collect payment data
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
     );
73 73
 
74 74
     // Record the pending payment
75
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
75
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
76 76
 
77
-    if ( !empty( $invoice ) ) {
78
-        $authorizenet_card  = !empty( $_POST['authorizenet'] ) ? $_POST['authorizenet'] : array();
77
+    if (!empty($invoice)) {
78
+        $authorizenet_card  = !empty($_POST['authorizenet']) ? $_POST['authorizenet'] : array();
79 79
         $card_defaults      = array(
80 80
             'cc_owner'          => $invoice->get_user_full_name(),
81 81
             'cc_number'         => false,
@@ -83,178 +83,178 @@  discard block
 block discarded – undo
83 83
             'cc_expire_year'    => false,
84 84
             'cc_cvv2'           => false,
85 85
         );
86
-        $authorizenet_card = wp_parse_args( $authorizenet_card, $card_defaults );
86
+        $authorizenet_card = wp_parse_args($authorizenet_card, $card_defaults);
87 87
 
88
-        if ( empty( $authorizenet_card['cc_owner'] ) ) {
89
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
88
+        if (empty($authorizenet_card['cc_owner'])) {
89
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
90 90
         }
91
-        if ( empty( $authorizenet_card['cc_number'] ) ) {
92
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
91
+        if (empty($authorizenet_card['cc_number'])) {
92
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
93 93
         }
94
-        if ( empty( $authorizenet_card['cc_expire_month'] ) ) {
95
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
94
+        if (empty($authorizenet_card['cc_expire_month'])) {
95
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
96 96
         }
97
-        if ( empty( $authorizenet_card['cc_expire_year'] ) ) {
98
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
97
+        if (empty($authorizenet_card['cc_expire_year'])) {
98
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
99 99
         }
100
-        if ( empty( $authorizenet_card['cc_cvv2'] ) ) {
101
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
100
+        if (empty($authorizenet_card['cc_cvv2'])) {
101
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
102 102
         }
103 103
 
104 104
         $errors = wpinv_get_errors();
105 105
 
106
-        if ( empty( $errors ) ) {
106
+        if (empty($errors)) {
107 107
             $invoice_id = $invoice->ID;
108 108
             $quantities_enabled = wpinv_item_quantities_enabled();
109 109
             $use_taxes          = wpinv_use_taxes();
110 110
 
111 111
             $authorizeAIM = wpinv_authorizenet_AIM();
112
-            $authorizeAIM->first_name       = wpinv_utf8_substr( $invoice->get_first_name(), 0, 50 );
113
-            $authorizeAIM->last_name        = wpinv_utf8_substr( $invoice->get_last_name(), 0, 50 );
114
-            $authorizeAIM->company          = wpinv_utf8_substr( $invoice->company, 0, 50 );
115
-            $authorizeAIM->address          = wpinv_utf8_substr( wp_strip_all_tags( $invoice->get_address(), true ), 0, 60 );
116
-            $authorizeAIM->city             = wpinv_utf8_substr( $invoice->city, 0, 40 );
117
-            $authorizeAIM->state            = wpinv_utf8_substr( $invoice->state, 0, 40 );
118
-            $authorizeAIM->zip              = wpinv_utf8_substr( $invoice->zip, 0, 40 );
119
-            $authorizeAIM->country          = wpinv_utf8_substr( $invoice->country, 0, 60 );
120
-            $authorizeAIM->phone            = wpinv_utf8_substr( $invoice->phone, 0, 25 );
121
-            $authorizeAIM->email            = wpinv_utf8_substr( $invoice->get_email(), 0, 255 );
122
-            $authorizeAIM->amount           = wpinv_sanitize_amount( $invoice->get_total() );
123
-            $authorizeAIM->card_num         = str_replace( ' ', '', sanitize_text_field( $authorizenet_card['cc_number'] ) );
124
-            $authorizeAIM->exp_date         = sanitize_text_field( $authorizenet_card['cc_expire_month'] ) . sanitize_text_field( $authorizenet_card['cc_expire_year'] );
125
-            $authorizeAIM->card_code        = sanitize_text_field( $authorizenet_card['cc_cvv2'] );
112
+            $authorizeAIM->first_name       = wpinv_utf8_substr($invoice->get_first_name(), 0, 50);
113
+            $authorizeAIM->last_name        = wpinv_utf8_substr($invoice->get_last_name(), 0, 50);
114
+            $authorizeAIM->company          = wpinv_utf8_substr($invoice->company, 0, 50);
115
+            $authorizeAIM->address          = wpinv_utf8_substr(wp_strip_all_tags($invoice->get_address(), true), 0, 60);
116
+            $authorizeAIM->city             = wpinv_utf8_substr($invoice->city, 0, 40);
117
+            $authorizeAIM->state            = wpinv_utf8_substr($invoice->state, 0, 40);
118
+            $authorizeAIM->zip              = wpinv_utf8_substr($invoice->zip, 0, 40);
119
+            $authorizeAIM->country          = wpinv_utf8_substr($invoice->country, 0, 60);
120
+            $authorizeAIM->phone            = wpinv_utf8_substr($invoice->phone, 0, 25);
121
+            $authorizeAIM->email            = wpinv_utf8_substr($invoice->get_email(), 0, 255);
122
+            $authorizeAIM->amount           = wpinv_sanitize_amount($invoice->get_total());
123
+            $authorizeAIM->card_num         = str_replace(' ', '', sanitize_text_field($authorizenet_card['cc_number']));
124
+            $authorizeAIM->exp_date         = sanitize_text_field($authorizenet_card['cc_expire_month']) . sanitize_text_field($authorizenet_card['cc_expire_year']);
125
+            $authorizeAIM->card_code        = sanitize_text_field($authorizenet_card['cc_cvv2']);
126 126
             $authorizeAIM->invoice_num      = $invoice->ID;
127 127
 
128 128
             $item_desc = array();
129
-            foreach ( $invoice->get_cart_details() as $item ) {            
130
-                $quantity       = $quantities_enabled && !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
-                $item_name      = wpinv_utf8_substr( $item['name'], 0, 31 );
132
-                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')';
129
+            foreach ($invoice->get_cart_details() as $item) {            
130
+                $quantity       = $quantities_enabled && !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
+                $item_name      = wpinv_utf8_substr($item['name'], 0, 31);
132
+                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
133 133
 
134
-                $authorizeAIM->addLineItem( $item['id'], $item_name, '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) );
134
+                $authorizeAIM->addLineItem($item['id'], $item_name, '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N'));
135 135
             }
136 136
 
137
-            $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc );
137
+            $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc);
138 138
 
139
-            if ( $use_taxes && $invoice->get_tax() > 0 ) {
140
-                $authorizeAIM->tax  = $invoice->get_tax();
139
+            if ($use_taxes && $invoice->get_tax() > 0) {
140
+                $authorizeAIM->tax = $invoice->get_tax();
141 141
 
142
-                $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
142
+                $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
143 143
             }
144 144
 
145
-            if ( $invoice->get_discount() > 0 ) {
146
-                $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) );
145
+            if ($invoice->get_discount() > 0) {
146
+                $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true));
147 147
             }
148 148
 
149
-            $item_description = wpinv_utf8_substr( $item_desc, 0, 255 );
150
-            $item_description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' );
149
+            $item_description = wpinv_utf8_substr($item_desc, 0, 255);
150
+            $item_description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8');
151 151
 
152
-            $authorizeAIM->description  = wpinv_utf8_substr( $item_description, 0, 255 );
152
+            $authorizeAIM->description = wpinv_utf8_substr($item_description, 0, 255);
153 153
 
154 154
             $is_recurring = $invoice->is_recurring(); // Recurring payment.
155 155
 
156
-            if ( $is_recurring ) {
156
+            if ($is_recurring) {
157 157
                 $authorizeAIM->recurring_billing = true;
158 158
             }
159 159
 
160 160
             try {
161
-                if ( $is_recurring ) {
161
+                if ($is_recurring) {
162 162
                     $response = $authorizeAIM->authorizeOnly();
163 163
                 } else {
164 164
                     $response = $authorizeAIM->authorizeAndCapture();
165 165
                 }
166 166
 
167
-                if ( $response->approved || $response->held ) {
168
-                    if ( $response->approved ) {
169
-                        wpinv_update_payment_status( $invoice_id, 'publish' );
167
+                if ($response->approved || $response->held) {
168
+                    if ($response->approved) {
169
+                        wpinv_update_payment_status($invoice_id, 'publish');
170 170
                     }
171
-                    wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id );
171
+                    wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id);
172 172
 
173
-                    wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment response: %s', 'invoicing' ), $response->response_reason_text ), '', '', true );
174
-                    wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing' ), $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code ), '', '', true );
173
+                    wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment response: %s', 'invoicing'), $response->response_reason_text), '', '', true);
174
+                    wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing'), $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code), '', '', true);
175 175
 
176
-                    do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card );
176
+                    do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card);
177 177
 
178 178
                     wpinv_clear_errors();
179 179
                     wpinv_empty_cart();
180 180
 
181
-                    wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
181
+                    wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
182 182
                 } else {
183
-                    if ( !empty( $response->response_reason_text ) ) {
184
-                        $error = __( $response->response_reason_text, 'invoicing' );
185
-                    } else if ( !empty( $response->error_message ) ) {
186
-                        $error = __( $response->error_message, 'invoicing' );
183
+                    if (!empty($response->response_reason_text)) {
184
+                        $error = __($response->response_reason_text, 'invoicing');
185
+                    } else if (!empty($response->error_message)) {
186
+                        $error = __($response->error_message, 'invoicing');
187 187
                     } else {
188
-                        $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) );
188
+                        $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true));
189 189
                     } 
190 190
 
191
-                    $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error );
191
+                    $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error);
192 192
 
193
-                    wpinv_set_error( 'payment_error', $error );
194
-                    wpinv_record_gateway_error( $error, $response );
195
-                    wpinv_insert_payment_note( $invoice_id, $error, '', '', true );
193
+                    wpinv_set_error('payment_error', $error);
194
+                    wpinv_record_gateway_error($error, $response);
195
+                    wpinv_insert_payment_note($invoice_id, $error, '', '', true);
196 196
 
197
-                    wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
197
+                    wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
198 198
                 }
199
-            } catch ( AuthorizeNetException $e ) {
200
-                wpinv_set_error( 'request_error', $e->getMessage() );
201
-                wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) );
202
-                wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
199
+            } catch (AuthorizeNetException $e) {
200
+                wpinv_set_error('request_error', $e->getMessage());
201
+                wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage()));
202
+                wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
203 203
             }
204 204
         } else {
205
-            wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
205
+            wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
206 206
         }
207 207
     } else {
208
-        wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing' ), print_r( $payment_data, true ) ), $invoice );
209
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
208
+        wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing'), print_r($payment_data, true)), $invoice);
209
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
210 210
     }
211 211
 }
212
-add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' );
212
+add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment');
213 213
 
214
-function wpinv_authorizenet_cancel_subscription( $subscription = '' ) {
215
-    if ( empty( $subscription->id ) ) {
214
+function wpinv_authorizenet_cancel_subscription($subscription = '') {
215
+    if (empty($subscription->id)) {
216 216
         return false;
217 217
     }
218 218
 
219 219
     try {
220 220
         $authnetXML = wpinv_authorizenet_XML();
221
-        $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription->id ) );
221
+        $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription->id));
222 222
 
223
-        if ( wpinv_is_test_mode( 'authorizenet' ) ) {
223
+        if (wpinv_is_test_mode('authorizenet')) {
224 224
             return true;
225 225
         }
226 226
 
227 227
         return $authnetXML->isSuccessful();
228
-    } catch( Exception $e ) {
229
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
228
+    } catch (Exception $e) {
229
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
230 230
     }
231 231
 
232 232
     return false;
233 233
 }
234
-add_action( 'wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_authorizenet_cancel_subscription' );
234
+add_action('wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_authorizenet_cancel_subscription');
235 235
 
236
-function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) {
237
-    $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' );
238
-    if ( empty( $authorizenet_md5_hash ) ) {
236
+function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) {
237
+    $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash');
238
+    if (empty($authorizenet_md5_hash)) {
239 239
         return true;
240 240
     }
241 241
 
242
-    $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) );
242
+    $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount));
243 243
 
244
-    return hash_equals( $compare_md5, $md5_hash );
244
+    return hash_equals($compare_md5, $md5_hash);
245 245
 }
246 246
 
247 247
 function wpinv_authorizenet_AIM() {
248
-    if ( !class_exists( 'AuthorizeNetException' ) ) {
249
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
248
+    if (!class_exists('AuthorizeNetException')) {
249
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
250 250
     }
251 251
 
252
-    $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) );
252
+    $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'));
253 253
 
254
-    if ( wpinv_is_test_mode( 'authorizenet' ) ) {
255
-        $authorizeAIM->setSandbox( true );
254
+    if (wpinv_is_test_mode('authorizenet')) {
255
+        $authorizeAIM->setSandbox(true);
256 256
     } else {
257
-        $authorizeAIM->setSandbox( false );
257
+        $authorizeAIM->setSandbox(false);
258 258
     }
259 259
 
260 260
     $authorizeAIM->customer_ip = wpinv_get_ip();
@@ -263,249 +263,249 @@  discard block
 block discarded – undo
263 263
 }
264 264
 
265 265
 function wpinv_authorizenet_XML() {
266
-    if ( !class_exists( 'AuthnetXML' ) ) {
267
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
266
+    if (!class_exists('AuthnetXML')) {
267
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
268 268
     }
269 269
     
270
-    $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) );
270
+    $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet'));
271 271
     
272 272
     return $authnetXML;
273 273
 }
274 274
 
275
-function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) {
276
-    if ( empty( $response ) || empty( $invoice ) ) {
275
+function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) {
276
+    if (empty($response) || empty($invoice)) {
277 277
         return false;
278 278
     }
279 279
 
280
-    if ( $invoice->is_recurring() && !empty( $response->approved ) ) {
281
-        $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info );
280
+    if ($invoice->is_recurring() && !empty($response->approved)) {
281
+        $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info);
282 282
         $success = false;
283
-        if ( wpinv_is_test_mode( 'authorizenet' ) ) {
283
+        if (wpinv_is_test_mode('authorizenet')) {
284 284
             $success = true;
285 285
         } else {
286 286
             $success = $subscription->isSuccessful();
287 287
         }
288 288
 
289
-        if ( !empty( $subscription ) && $success ) {
290
-            do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' );
289
+        if (!empty($subscription) && $success) {
290
+            do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet');
291 291
 
292
-            wpinv_authorizenet_subscription_record_signup( $subscription, $invoice );
292
+            wpinv_authorizenet_subscription_record_signup($subscription, $invoice);
293 293
 
294
-            do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' );
294
+            do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet');
295 295
         } else {
296
-            if ( isset( $subscription->messages->message ) ) {
296
+            if (isset($subscription->messages->message)) {
297 297
                 $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text;
298
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' );
298
+                wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing');
299 299
             } else {
300
-                $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' );
301
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error );
300
+                $error = __('Your subscription cannot be created due to an error.', 'invoicing');
301
+                wpinv_set_error('wpinv_authorize_recurring_error', $error);
302 302
             }
303 303
 
304
-            wpinv_record_gateway_error( $error, $subscription );
304
+            wpinv_record_gateway_error($error, $subscription);
305 305
 
306
-            wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ), '', '', true );
306
+            wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error), '', '', true);
307 307
         }
308 308
     }
309 309
 }
310
-add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 );
310
+add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3);
311 311
 
312
-function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) {
313
-    if ( empty( $invoice ) ) {
312
+function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) {
313
+    if (empty($invoice)) {
314 314
         return false;
315 315
     }
316 316
 
317
-    $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response );
317
+    $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response);
318 318
 
319 319
     try {
320 320
         $authnetXML = wpinv_authorizenet_XML();
321
-        $authnetXML->ARBCreateSubscriptionRequest( $params );
322
-    } catch( Exception $e ) {
321
+        $authnetXML->ARBCreateSubscriptionRequest($params);
322
+    } catch (Exception $e) {
323 323
         $authnetXML = array();
324
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
324
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
325 325
     }
326 326
 
327 327
     return $authnetXML;
328 328
 }
329 329
 
330
-function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) {
331
-    if ( empty( $invoice ) ) {
330
+function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) {
331
+    if (empty($invoice)) {
332 332
         return false;
333 333
     }
334 334
 
335
-    $subscription_item = $invoice->get_recurring( true );
336
-    if ( empty( $subscription_item->ID ) ) {
335
+    $subscription_item = $invoice->get_recurring(true);
336
+    if (empty($subscription_item->ID)) {
337 337
         return false;
338 338
     }
339 339
 
340
-    $item = $invoice->get_recurring( true );
340
+    $item = $invoice->get_recurring(true);
341 341
 
342
-    if ( empty( $item ) ) {
342
+    if (empty($item)) {
343 343
         $name = '';
344 344
     }
345 345
 
346
-    if ( !( $name = $item->get_name() ) ) {
346
+    if (!($name = $item->get_name())) {
347 347
         $name = $item->post_name;
348 348
     }
349 349
 
350
-    $card_details       = wpinv_authorizenet_generate_card_info( $card_info );
350
+    $card_details       = wpinv_authorizenet_generate_card_info($card_info);
351 351
     $subscription_name  = $invoice->get_subscription_name();
352
-    $initial_amount     = wpinv_round_amount( $invoice->get_total() );
353
-    $recurring_amount   = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) );
352
+    $initial_amount     = wpinv_round_amount($invoice->get_total());
353
+    $recurring_amount   = wpinv_round_amount($invoice->get_recurring_details('total'));
354 354
     $interval           = $subscription_item->get_recurring_interval();
355 355
     $period             = $subscription_item->get_recurring_period();
356 356
     $bill_times         = (int)$subscription_item->get_recurring_limit();
357 357
     $bill_times         = $bill_times > 0 ? $bill_times : 9999;
358 358
 
359
-    $time_period        = wpinv_authorizenet_get_time_period( $interval, $period );
359
+    $time_period        = wpinv_authorizenet_get_time_period($interval, $period);
360 360
     $interval           = $time_period['interval'];
361 361
     $period             = $time_period['period'];
362 362
 
363 363
     $current_tz = date_default_timezone_get();
364
-    date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
365
-    $today = date( 'Y-m-d' );
366
-    date_default_timezone_set( $current_tz );
364
+    date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
365
+    $today = date('Y-m-d');
366
+    date_default_timezone_set($current_tz);
367 367
 
368 368
     $free_trial = $invoice->is_free_trial();
369
-    if ( $free_trial && $subscription_item->has_free_trial() ) {
369
+    if ($free_trial && $subscription_item->has_free_trial()) {
370 370
         $trial_interval    = $subscription_item->get_trial_interval();
371
-        $trial_period      = $subscription_item->get_trial_period( true );
371
+        $trial_period      = $subscription_item->get_trial_period(true);
372 372
     }
373 373
 
374 374
     $subscription = array();
375 375
     $subscription['name'] = $subscription_name;
376 376
 
377 377
     $subscription['paymentSchedule'] = array(
378
-        'interval'         => array( 'length' => $interval, 'unit' => $period ),
378
+        'interval'         => array('length' => $interval, 'unit' => $period),
379 379
         'startDate'        => $today,
380 380
         'totalOccurrences' => $bill_times,
381
-        'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0,
381
+        'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0,
382 382
     );
383 383
 
384 384
     $subscription['amount'] = $recurring_amount;
385 385
     $subscription['trialAmount'] = $initial_amount;
386
-    $subscription['payment'] = array( 'creditCard' => $card_details );
387
-    $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() );
388
-    $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone );
386
+    $subscription['payment'] = array('creditCard' => $card_details);
387
+    $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number());
388
+    $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone);
389 389
 
390 390
     $subscription['billTo'] = array(
391 391
         'firstName' => $invoice->get_first_name(),
392 392
         'lastName'  => $invoice->get_last_name(),
393 393
         'company'   => $invoice->company,
394
-        'address'   => wp_strip_all_tags( $invoice->get_address(), true ),
394
+        'address'   => wp_strip_all_tags($invoice->get_address(), true),
395 395
         'city'      => $invoice->city,
396 396
         'state'     => $invoice->state,
397 397
         'zip'       => $invoice->zip,
398 398
         'country'   => $invoice->country,
399 399
     );
400 400
 
401
-    $params = array( 'subscription' => $subscription );
401
+    $params = array('subscription' => $subscription);
402 402
 
403
-    return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response );
403
+    return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response);
404 404
 }
405 405
 
406
-function wpinv_authorizenet_generate_card_info( $card_info = array() ) {
407
-    $card_defaults      = array(
406
+function wpinv_authorizenet_generate_card_info($card_info = array()) {
407
+    $card_defaults = array(
408 408
         'cc_owner'          => null,
409 409
         'cc_number'         => null,
410 410
         'cc_expire_month'   => null,
411 411
         'cc_expire_year'    => null,
412 412
         'cc_cvv2'           => null,
413 413
     );
414
-    $card_info = wp_parse_args( $card_info, $card_defaults );
414
+    $card_info = wp_parse_args($card_info, $card_defaults);
415 415
 
416 416
     $card_details = array(
417
-        'cardNumber'     => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ),
418
-        'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ),
419
-        'cardCode'       => sanitize_text_field( $card_info['cc_cvv2'] ),
417
+        'cardNumber'     => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])),
418
+        'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']),
419
+        'cardCode'       => sanitize_text_field($card_info['cc_cvv2']),
420 420
     );
421 421
 
422 422
     return $card_details;
423 423
 }
424 424
 
425
-function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) {
426
-    $parent_invoice_id = absint( $invoice->ID );
425
+function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) {
426
+    $parent_invoice_id = absint($invoice->ID);
427 427
 
428
-    if( empty( $parent_invoice_id ) ) {
428
+    if (empty($parent_invoice_id)) {
429 429
         return;
430 430
     }
431 431
 
432
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
433
-    if ( empty( $invoice ) ) {
432
+    $invoice = wpinv_get_invoice($parent_invoice_id);
433
+    if (empty($invoice)) {
434 434
         return;
435 435
     }
436 436
 
437 437
     $subscriptionId     = (array)$subscription->subscriptionId;
438
-    $subscription_id    = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id;
438
+    $subscription_id    = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id;
439 439
 
440
-    wpinv_set_payment_transaction_id( $parent_invoice_id, $subscription_id );
440
+    wpinv_set_payment_transaction_id($parent_invoice_id, $subscription_id);
441 441
 
442
-    $subscription = wpinv_get_authorizenet_subscription( $subscription, $parent_invoice_id );
442
+    $subscription = wpinv_get_authorizenet_subscription($subscription, $parent_invoice_id);
443 443
 
444
-    if ( false === $subscription ) {
444
+    if (false === $subscription) {
445 445
         return;
446 446
     }
447 447
 
448 448
     // Set payment to complete
449
-    wpinv_update_payment_status( $subscription->parent_payment_id, 'publish' );
449
+    wpinv_update_payment_status($subscription->parent_payment_id, 'publish');
450 450
     sleep(1);
451
-    wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ), '', '', true );
452
-    update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $subscription_id);
451
+    wpinv_insert_payment_note($parent_invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id), '', '', true);
452
+    update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $subscription_id);
453 453
 
454 454
     $status = 'trialling' == $subscription->status ? 'trialling' : 'active';
455 455
 
456 456
     // Retrieve pending subscription from database and update it's status to active and set proper profile ID
457
-    $subscription->update( array( 'profile_id' => $subscription_id, 'status' => $status ) );
457
+    $subscription->update(array('profile_id' => $subscription_id, 'status' => $status));
458 458
 }
459 459
 
460
-function wpinv_authorizenet_validate_checkout( $valid_data, $post ) {
461
-    if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) {
460
+function wpinv_authorizenet_validate_checkout($valid_data, $post) {
461
+    if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') {
462 462
         $error = false;
463 463
         
464
-        if ( empty( $post['authorizenet']['cc_owner'] ) ) {
464
+        if (empty($post['authorizenet']['cc_owner'])) {
465 465
             $error = true;
466
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
466
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
467 467
         }
468
-        if ( empty( $post['authorizenet']['cc_number'] ) ) {
468
+        if (empty($post['authorizenet']['cc_number'])) {
469 469
             $error = true;
470
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
470
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
471 471
         }
472
-        if ( empty( $post['authorizenet']['cc_expire_month'] ) ) {
472
+        if (empty($post['authorizenet']['cc_expire_month'])) {
473 473
             $error = true;
474
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
474
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
475 475
         }
476
-        if ( empty( $post['authorizenet']['cc_expire_year'] ) ) {
476
+        if (empty($post['authorizenet']['cc_expire_year'])) {
477 477
             $error = true;
478
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
478
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
479 479
         }
480
-        if ( empty( $post['authorizenet']['cc_cvv2'] ) ) {
480
+        if (empty($post['authorizenet']['cc_cvv2'])) {
481 481
             $error = true;
482
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
482
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
483 483
         }
484 484
 
485
-        if ( $error ) {
485
+        if ($error) {
486 486
             return;
487 487
         }
488 488
 
489 489
         $invoice = wpinv_get_invoice_cart();
490 490
 
491
-        if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) {
492
-            $subscription_item = $invoice->get_recurring( true );
491
+        if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) {
492
+            $subscription_item = $invoice->get_recurring(true);
493 493
 
494 494
             $interval   = $subscription_item->get_recurring_interval();
495 495
             $period     = $subscription_item->get_recurring_period();
496 496
 
497
-            if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) {
498
-                wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) );
497
+            if ($period == 'D' && ($interval < 7 || $interval > 365)) {
498
+                wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing'));
499 499
             }
500 500
         }
501 501
     }
502 502
 }
503
-add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 );
503
+add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2);
504 504
 
505
-function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) {
506
-    $subscription_interval = absint( $subscription_interval );
505
+function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) {
506
+    $subscription_interval = absint($subscription_interval);
507 507
 
508
-    switch( $subscription_period ) {
508
+    switch ($subscription_period) {
509 509
         case 'W':
510 510
         case 'week':
511 511
         case 'weeks':
@@ -515,14 +515,14 @@  discard block
 block discarded – undo
515 515
         case 'M':
516 516
         case 'month':
517 517
         case 'months':
518
-            if ( $subscription_interval > 12 ) {
518
+            if ($subscription_interval > 12) {
519 519
                 $subscription_interval = 12;
520 520
             }
521 521
 
522 522
             $interval = $subscription_interval;
523 523
             $period   = 'months';
524 524
             
525
-            if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) {
525
+            if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) {
526 526
                 $interval = $subscription_interval * 30;
527 527
                 $period   = 'days';
528 528
             }
@@ -539,30 +539,30 @@  discard block
 block discarded – undo
539 539
             break;
540 540
     }
541 541
 
542
-    return compact( 'interval', 'period' );
542
+    return compact('interval', 'period');
543 543
 }
544 544
 
545 545
 function wpinv_authorizenet_process_ipn() {
546
-    if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) {
546
+    if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) {
547 547
         return;
548 548
     }
549 549
 
550
-    $subscription_id = !empty( $_POST['x_subscription_id'] ) ? intval( $_POST['x_subscription_id'] ) : false;
550
+    $subscription_id = !empty($_POST['x_subscription_id']) ? intval($_POST['x_subscription_id']) : false;
551 551
 
552
-    if ( $subscription_id ) {
553
-        $response_code  = intval( $_POST['x_response_code'] );
554
-        $reason_code    = intval( $_POST['x_response_reason_code'] );
552
+    if ($subscription_id) {
553
+        $response_code  = intval($_POST['x_response_code']);
554
+        $reason_code    = intval($_POST['x_response_reason_code']);
555 555
 
556
-        $subscription = new WPInv_Subscription( $subscription_id, true );
556
+        $subscription = new WPInv_Subscription($subscription_id, true);
557 557
 
558
-        if ( !$subscription->id ) {
558
+        if (!$subscription->id) {
559 559
             return;
560 560
         }
561 561
 
562
-        if ( 1 == $response_code ) {
562
+        if (1 == $response_code) {
563 563
             // Approved
564
-            $transaction_id = sanitize_text_field( $_POST['x_trans_id'] );
565
-            $renewal_amount = sanitize_text_field( $_POST['x_amount'] );
564
+            $transaction_id = sanitize_text_field($_POST['x_trans_id']);
565
+            $renewal_amount = sanitize_text_field($_POST['x_amount']);
566 566
 
567 567
             $args = array(
568 568
                 'amount'         => $renewal_amount,
@@ -570,63 +570,63 @@  discard block
 block discarded – undo
570 570
                 'gateway'        => 'authorizenet'
571 571
             );
572 572
 
573
-            $subscription->add_payment( $args );
573
+            $subscription->add_payment($args);
574 574
             $subscription->renew();
575 575
 
576
-            do_action( 'wpinv_recurring_authorizenet_silent_post_payment', $subscription );
577
-            do_action( 'wpinv_authorizenet_renewal_payment', $subscription );
578
-        } else if ( 2 == $response_code ) {
576
+            do_action('wpinv_recurring_authorizenet_silent_post_payment', $subscription);
577
+            do_action('wpinv_authorizenet_renewal_payment', $subscription);
578
+        } else if (2 == $response_code) {
579 579
             // Declined
580 580
             $subscription->failing();
581
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription );
582
-            do_action( 'wpinv_authorizenet_renewal_error', $subscription );
583
-        } else if ( 3 == $response_code || 8 == $reason_code ) {
581
+            do_action('wpinv_authorizenet_renewal_payment_failed', $subscription);
582
+            do_action('wpinv_authorizenet_renewal_error', $subscription);
583
+        } else if (3 == $response_code || 8 == $reason_code) {
584 584
             // An expired card
585 585
             $subscription->failing();
586
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription );
587
-            do_action( 'wpinv_authorizenet_renewal_error', $subscription );
586
+            do_action('wpinv_authorizenet_renewal_payment_failed', $subscription);
587
+            do_action('wpinv_authorizenet_renewal_error', $subscription);
588 588
         } else {
589 589
             // Other Error
590
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription );
590
+            do_action('wpinv_authorizenet_renewal_payment_error', $subscription);
591 591
         }
592 592
 
593 593
         exit;
594 594
     }
595 595
 }
596
-add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' );
596
+add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn');
597 597
 
598 598
 /**
599 599
  * Retrieve the subscription
600 600
  */
601
-function wpinv_get_authorizenet_subscription( $subscription_data = array(), $invoice_id ) {
602
-    $parent_invoice_id = absint( $invoice_id );
601
+function wpinv_get_authorizenet_subscription($subscription_data = array(), $invoice_id) {
602
+    $parent_invoice_id = absint($invoice_id);
603 603
 
604
-    if ( empty( $subscription_data ) ) {
604
+    if (empty($subscription_data)) {
605 605
         return false;
606 606
     }
607 607
 
608
-    if ( empty( $parent_invoice_id ) ) {
608
+    if (empty($parent_invoice_id)) {
609 609
         return false;
610 610
     }
611 611
 
612
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
613
-    if ( empty( $invoice ) ) {
612
+    $invoice = wpinv_get_invoice($parent_invoice_id);
613
+    if (empty($invoice)) {
614 614
         return false;
615 615
     }
616 616
 
617 617
     $subscriptionId     = (array)$subscription_data->subscriptionId;
618
-    $subscription_id    = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id;
618
+    $subscription_id    = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id;
619 619
 
620
-    $subscription = new WPInv_Subscription( $subscription_id, true );
620
+    $subscription = new WPInv_Subscription($subscription_id, true);
621 621
 
622
-    if ( ! $subscription || $subscription->id < 1 ) {
622
+    if (!$subscription || $subscription->id < 1) {
623 623
         $subs_db      = new WPInv_Subscriptions_DB;
624
-        $subs         = $subs_db->get_subscriptions( array( 'parent_payment_id' => $parent_invoice_id, 'number' => 1 ) );
625
-        $subscription = reset( $subs );
624
+        $subs         = $subs_db->get_subscriptions(array('parent_payment_id' => $parent_invoice_id, 'number' => 1));
625
+        $subscription = reset($subs);
626 626
 
627
-        if ( $subscription && $subscription->id > 0 ) {
627
+        if ($subscription && $subscription->id > 0) {
628 628
             // Update the profile ID so it is set for future renewals
629
-            $subscription->update( array( 'profile_id' => sanitize_text_field( $subscription_id ) ) );
629
+            $subscription->update(array('profile_id' => sanitize_text_field($subscription_id)));
630 630
         } else {
631 631
             // No subscription found with a matching payment ID, bail
632 632
             return false;
@@ -637,12 +637,12 @@  discard block
 block discarded – undo
637 637
 }
638 638
 
639 639
 function wpinv_is_authorizenet_valid_for_use() {
640
-    return in_array( wpinv_get_currency(), apply_filters( 'wpinv_authorizenet_supported_currencies', array( 'AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR' ) ) );
640
+    return in_array(wpinv_get_currency(), apply_filters('wpinv_authorizenet_supported_currencies', array('AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR')));
641 641
 }
642
-function wpinv_check_authorizenet_currency_support( $gateway_list ) {
643
-    if ( isset( $gateway_list['authorizenet'] ) && ! wpinv_is_authorizenet_valid_for_use() ) {
644
-        unset( $gateway_list['authorizenet'] );
642
+function wpinv_check_authorizenet_currency_support($gateway_list) {
643
+    if (isset($gateway_list['authorizenet']) && !wpinv_is_authorizenet_valid_for_use()) {
644
+        unset($gateway_list['authorizenet']);
645 645
     }
646 646
     return $gateway_list;
647 647
 }
648
-add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1 );
649 648
\ No newline at end of file
649
+add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1);
650 650
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/worldpay.php 1 patch
Spacing   +65 added lines, -65 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_worldpay_cc_form', '__return_false' );
5
+add_action('wpinv_worldpay_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_worldpay_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_worldpay_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,132 +24,132 @@  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 ) ) {
29
+    if (!empty($invoice)) {
30 30
         $quantities_enabled = wpinv_item_quantities_enabled();
31 31
         
32
-        $instId     = wpinv_get_option( 'worldpay_instId', false );
32
+        $instId     = wpinv_get_option('worldpay_instId', false);
33 33
         $cartId     = $invoice->get_number();
34
-        $testMode   = wpinv_is_test_mode( 'worldpay' ) ? 100 : 0;
34
+        $testMode   = wpinv_is_test_mode('worldpay') ? 100 : 0;
35 35
         $name       = $invoice->get_user_full_name();
36
-        $address    = wp_strip_all_tags( $invoice->get_address(), true );
36
+        $address    = wp_strip_all_tags($invoice->get_address(), true);
37 37
         $postcode   = $invoice->zip;
38 38
         $tel        = $invoice->phone;
39 39
         $email      = $invoice->get_email();
40 40
         $country    = $invoice->country;
41
-        $amount     = wpinv_sanitize_amount( $invoice->get_total() );
41
+        $amount     = wpinv_sanitize_amount($invoice->get_total());
42 42
         $currency   = wpinv_get_currency();
43 43
         
44 44
         $items      = array();
45
-        foreach ( $invoice->get_cart_details() as $item ) {
45
+        foreach ($invoice->get_cart_details() as $item) {
46 46
             $item_desc  = $item['name'];
47
-            $quantity   = !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1;
48
-            $item_desc .= ' (' . ( $quantities_enabled ? $quantity . 'x ' : '' ) . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')';
47
+            $quantity   = !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1;
48
+            $item_desc .= ' (' . ($quantities_enabled ? $quantity . 'x ' : '') . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
49 49
             
50 50
             $items[] = $item_desc;
51 51
         }
52 52
         
53
-        $desc = implode( ', ', $items );
54
-        if ( wpinv_use_taxes() && $invoice->get_tax() > 0 ) {
55
-            $desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
53
+        $desc = implode(', ', $items);
54
+        if (wpinv_use_taxes() && $invoice->get_tax() > 0) {
55
+            $desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
56 56
         }
57 57
         
58 58
         $extra_params                   = array();
59 59
         $extra_params['MC_description'] = $desc;
60
-        $extra_params['MC_callback']    = wpinv_get_ipn_url( 'worldpay' );
60
+        $extra_params['MC_callback']    = wpinv_get_ipn_url('worldpay');
61 61
         $extra_params['MC_key']         = $invoice->get_key();
62 62
         $extra_params['MC_invoice_id']  = $invoice->ID;
63 63
         $extra_params['address1']       = $address;
64 64
         $extra_params['town']           = $invoice->city;
65 65
         $extra_params['region']         = $invoice->state;
66
-        $extra_params['amountString']   = $invoice->get_total( true );
67
-        $extra_params['countryString']  = wpinv_country_name( $invoice->country );
66
+        $extra_params['amountString']   = $invoice->get_total(true);
67
+        $extra_params['countryString']  = wpinv_country_name($invoice->country);
68 68
         $extra_params['compName']       = $invoice->company;
69 69
         
70
-        $extra_params   = apply_filters( 'wpinv_worldpay_form_extra_parameters', $extra_params, $invoice );
70
+        $extra_params   = apply_filters('wpinv_worldpay_form_extra_parameters', $extra_params, $invoice);
71 71
         
72
-        $redirect_text  = __( 'Redirecting to Worldpay site, click on button if not redirected.', 'invoicing' );
73
-        $redirect_text  = apply_filters( 'wpinv_worldpay_redirect_text', $redirect_text, $invoice );
72
+        $redirect_text  = __('Redirecting to Worldpay site, click on button if not redirected.', 'invoicing');
73
+        $redirect_text  = apply_filters('wpinv_worldpay_redirect_text', $redirect_text, $invoice);
74 74
         
75 75
         // Empty the shopping cart
76 76
         wpinv_empty_cart();
77 77
         ?>
78 78
 <div class="wpi-worldpay-form" style="padding:20px;font-family:arial,sans-serif;text-align:center;color:#555">
79
-<?php do_action( 'wpinv_worldpay_form_before', $invoice ); ?>
80
-<h3><?php echo $redirect_text ;?></h3>
79
+<?php do_action('wpinv_worldpay_form_before', $invoice); ?>
80
+<h3><?php echo $redirect_text; ?></h3>
81 81
 <form action="<?php echo wpinv_get_worldpay_redirect(); ?>" name="wpi_worldpay_form" method="POST">
82
-    <input type="hidden" value="<?php echo $amount;?>" name="amount">
83
-    <input type="hidden" value="<?php echo esc_attr( $cartId );?>" name="cartId">
84
-    <input type="hidden" value="<?php echo $currency;?>" name="currency">
85
-    <input type="hidden" value="<?php echo $instId;?>" name="instId">
86
-    <input type="hidden" value="<?php echo $testMode;?>" name="testMode">
87
-    <input type="hidden" value="<?php echo esc_attr( $name );?>" name="name">
88
-    <input type="hidden" value="<?php echo esc_attr( $address );?>" name="address">
89
-    <input type="hidden" value="<?php echo esc_attr( $postcode );?>" name="postcode">
90
-    <input type="hidden" value="<?php echo esc_attr( $tel );?>" name="tel">
91
-    <input type="hidden" value="<?php echo esc_attr( $email );?>" name="email">
92
-    <input type="hidden" value="<?php echo esc_attr( $country );?>" name="country">
93
-    <input type="hidden" value="<?php echo esc_attr( $desc );?>" name="desc">
94
-    <?php foreach ( $extra_params as $param => $value ) { ?>
95
-        <?php if ( !empty( $value !== false ) ) { ?>
96
-    <input type="hidden" value="<?php echo esc_attr( $value );?>" name="<?php echo esc_attr( $param );?>">
82
+    <input type="hidden" value="<?php echo $amount; ?>" name="amount">
83
+    <input type="hidden" value="<?php echo esc_attr($cartId); ?>" name="cartId">
84
+    <input type="hidden" value="<?php echo $currency; ?>" name="currency">
85
+    <input type="hidden" value="<?php echo $instId; ?>" name="instId">
86
+    <input type="hidden" value="<?php echo $testMode; ?>" name="testMode">
87
+    <input type="hidden" value="<?php echo esc_attr($name); ?>" name="name">
88
+    <input type="hidden" value="<?php echo esc_attr($address); ?>" name="address">
89
+    <input type="hidden" value="<?php echo esc_attr($postcode); ?>" name="postcode">
90
+    <input type="hidden" value="<?php echo esc_attr($tel); ?>" name="tel">
91
+    <input type="hidden" value="<?php echo esc_attr($email); ?>" name="email">
92
+    <input type="hidden" value="<?php echo esc_attr($country); ?>" name="country">
93
+    <input type="hidden" value="<?php echo esc_attr($desc); ?>" name="desc">
94
+    <?php foreach ($extra_params as $param => $value) { ?>
95
+        <?php if (!empty($value !== false)) { ?>
96
+    <input type="hidden" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($param); ?>">
97 97
         <?php } ?>
98 98
     <?php } ?>
99
-    <?php do_action( 'wpinv_worldpay_form_parameters', $invoice ); ?>
100
-    <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e( 'Pay by Debit/Credit Card (WorldPay)', 'invoicing' ) ;?>">
99
+    <?php do_action('wpinv_worldpay_form_parameters', $invoice); ?>
100
+    <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e('Pay by Debit/Credit Card (WorldPay)', 'invoicing'); ?>">
101 101
 </form>
102 102
 <script type="text/javascript">document.wpi_worldpay_form.submit();</script>
103
-<?php do_action( 'wpinv_worldpay_form_after', $invoice ); ?>
103
+<?php do_action('wpinv_worldpay_form_after', $invoice); ?>
104 104
 </div>
105 105
         <?php
106 106
     } else {
107
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
107
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
108 108
         // If errors are present, send the user back to the purchase page so they can be corrected
109
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
109
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
110 110
     }
111 111
 }
112
-add_action( 'wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment' );
112
+add_action('wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment');
113 113
 
114 114
 function wpinv_get_worldpay_redirect() {
115
-    $redirect = wpinv_is_test_mode( 'worldpay' ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
115
+    $redirect = wpinv_is_test_mode('worldpay') ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
116 116
     
117
-    return apply_filters( 'wpinv_worldpay_redirect', $redirect );
117
+    return apply_filters('wpinv_worldpay_redirect', $redirect);
118 118
 }
119 119
 
120 120
 function wpinv_process_worldpay_ipn() {
121
-    $request = wpinv_get_post_data( 'post' );
121
+    $request = wpinv_get_post_data('post');
122 122
     
123
-    if ( !empty( $request['cartId'] ) && !empty( $request['transStatus'] ) && !empty( $request['installation'] ) && isset( $request['testMode'] ) && isset( $request['MC_invoice_id'] ) && isset( $request['MC_key'] ) ) {
123
+    if (!empty($request['cartId']) && !empty($request['transStatus']) && !empty($request['installation']) && isset($request['testMode']) && isset($request['MC_invoice_id']) && isset($request['MC_key'])) {
124 124
         $invoice_id = $request['MC_invoice_id'];
125 125
         
126
-        if ( $invoice_id == wpinv_get_invoice_id_by_key( $request['MC_key'] ) && $invoice = wpinv_get_invoice( $invoice_id ) ) {
127
-            if ( $request['transStatus'] == 'Y' ) {                
128
-                wpinv_update_payment_status( $invoice_id, 'publish' );
129
-                wpinv_set_payment_transaction_id( $invoice_id, $request['transId'] );
130
-                wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Worldpay Transaction ID: %s', 'invoicing' ), $request['transId'] ) );
126
+        if ($invoice_id == wpinv_get_invoice_id_by_key($request['MC_key']) && $invoice = wpinv_get_invoice($invoice_id)) {
127
+            if ($request['transStatus'] == 'Y') {                
128
+                wpinv_update_payment_status($invoice_id, 'publish');
129
+                wpinv_set_payment_transaction_id($invoice_id, $request['transId']);
130
+                wpinv_insert_payment_note($invoice_id, sprintf(__('Worldpay Transaction ID: %s', 'invoicing'), $request['transId']));
131 131
                 return;
132
-            } else if ( $request['transStatus'] == 'C' ) {
133
-                wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
134
-                wpinv_insert_payment_note( $invoice_id, __( 'Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing' ) );
132
+            } else if ($request['transStatus'] == 'C') {
133
+                wpinv_update_payment_status($invoice_id, 'wpi-failed');
134
+                wpinv_insert_payment_note($invoice_id, __('Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing'));
135 135
                 
136
-                wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing' ), json_encode( $request ) ), $invoice_id );
136
+                wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing'), json_encode($request)), $invoice_id);
137 137
                 return;
138 138
             }
139 139
         }
140 140
     }
141 141
     return;
142 142
 }
143
-add_action( 'wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn' );
143
+add_action('wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn');
144 144
 
145 145
 function wpinv_is_worldpay_valid_for_use() {
146
-    return in_array( wpinv_get_currency(), apply_filters( 'wpinv_worldpay_supported_currencies', array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' )));
146
+    return in_array(wpinv_get_currency(), apply_filters('wpinv_worldpay_supported_currencies', array('AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR')));
147 147
 }
148 148
 
149
-function wpinv_check_worldpay_currency_support( $gateway_list ) {
150
-    if ( isset( $gateway_list['worldpay'] ) && ! wpinv_is_worldpay_valid_for_use() ) {
151
-        unset( $gateway_list['worldpay'] );
149
+function wpinv_check_worldpay_currency_support($gateway_list) {
150
+    if (isset($gateway_list['worldpay']) && !wpinv_is_worldpay_valid_for_use()) {
151
+        unset($gateway_list['worldpay']);
152 152
     }
153 153
     return $gateway_list;
154 154
 }
155
-add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1 );
156 155
\ No newline at end of file
156
+add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1);
157 157
\ No newline at end of file
Please login to merge, or discard this patch.