Passed
Push — master ( 90f5a7...bd1b00 )
by Stiofan
23s
created
includes/gateways/paypal.php 1 patch
Spacing   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_action( 'wpinv_paypal_cc_form', '__return_false' );
6
-add_filter( 'wpinv_paypal_support_subscription', '__return_true' );
5
+add_action('wpinv_paypal_cc_form', '__return_false');
6
+add_filter('wpinv_paypal_support_subscription', '__return_true');
7 7
 
8
-function wpinv_process_paypal_payment( $purchase_data ) {
9
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
10
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
8
+function wpinv_process_paypal_payment($purchase_data) {
9
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
10
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
11 11
     }
12 12
 
13 13
     // Collect payment data
@@ -21,34 +21,34 @@  discard block
 block discarded – undo
21 21
         'user_info'     => $purchase_data['user_info'],
22 22
         'cart_details'  => $purchase_data['cart_details'],
23 23
         'gateway'       => 'paypal',
24
-        'status'        => !empty( $purchase_data['buy_now'] ) ? 'private' : 'pending'
24
+        'status'        => !empty($purchase_data['buy_now']) ? 'private' : 'pending'
25 25
     );
26 26
 
27 27
     // Record the pending payment
28
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
28
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
29 29
 
30 30
     // Check payment
31
-    if ( ! $invoice ) {
31
+    if (!$invoice) {
32 32
         // Record the error
33
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $payment );
33
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $payment);
34 34
         // Problems? send back
35
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
35
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
36 36
     } else {
37 37
         // Only send to PayPal if the pending payment is created successfully
38
-        $listener_url = wpinv_get_ipn_url( 'paypal' );
38
+        $listener_url = wpinv_get_ipn_url('paypal');
39 39
 
40 40
         // Get the success url
41
-        $return_url = add_query_arg( array(
41
+        $return_url = add_query_arg(array(
42 42
                 'payment-confirm' => 'paypal',
43 43
                 'invoice-id' => $invoice->ID
44
-            ), get_permalink( wpinv_get_option( 'success_page', false ) ) );
44
+            ), get_permalink(wpinv_get_option('success_page', false)));
45 45
 
46 46
         // Get the PayPal redirect uri
47
-        $paypal_redirect = trailingslashit( wpinv_get_paypal_redirect() ) . '?';
47
+        $paypal_redirect = trailingslashit(wpinv_get_paypal_redirect()) . '?';
48 48
 
49 49
         // Setup PayPal arguments
50 50
         $paypal_args = array(
51
-            'business'      => wpinv_get_option( 'paypal_email', false ),
51
+            'business'      => wpinv_get_option('paypal_email', false),
52 52
             'email'         => $invoice->get_email(),
53 53
             'first_name'    => $invoice->get_first_name(),
54 54
             'last_name'     => $invoice->get_last_name(),
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
             'shipping'      => '0',
58 58
             'no_note'       => '1',
59 59
             'currency_code' => wpinv_get_currency(),
60
-            'charset'       => get_bloginfo( 'charset' ),
60
+            'charset'       => get_bloginfo('charset'),
61 61
             'custom'        => $invoice->ID,
62 62
             'rm'            => '2',
63 63
             'return'        => $return_url,
64
-            'cancel_return' => wpinv_get_failed_transaction_uri( '?invoice-id=' . $invoice->ID ),
64
+            'cancel_return' => wpinv_get_failed_transaction_uri('?invoice-id=' . $invoice->ID),
65 65
             'notify_url'    => $listener_url,
66
-            'cbt'           => get_bloginfo( 'name' ),
66
+            'cbt'           => get_bloginfo('name'),
67 67
             'bn'            => 'WPInvoicing_SP',
68 68
 	        'lc'            => 'US' // this will force paypal site to english
69 69
         );
@@ -79,57 +79,57 @@  discard block
 block discarded – undo
79 79
             'upload' => '1'
80 80
         );
81 81
 
82
-        $paypal_args = array_merge( $paypal_extra_args, $paypal_args );
82
+        $paypal_args = array_merge($paypal_extra_args, $paypal_args);
83 83
 
84 84
         // Add cart items
85 85
         $i = 1;
86
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
87
-            foreach ( $purchase_data['cart_details'] as $item ) {
86
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
87
+            foreach ($purchase_data['cart_details'] as $item) {
88 88
                 $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1;
89
-                $item_amount = round( $item['subtotal'] / $item['quantity'], 2 );
89
+                $item_amount = round($item['subtotal'] / $item['quantity'], 2);
90 90
 
91
-                if ( $item_amount <= 0 ) {
91
+                if ($item_amount <= 0) {
92 92
                     $item_amount = 0;
93 93
                 }
94 94
 
95
-                $paypal_args['item_number_' . $i ]      = $item['id'];
96
-                $paypal_args['item_name_' . $i ]        = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) );
97
-                $paypal_args['quantity_' . $i ]         = $item['quantity'];
98
-                $paypal_args['amount_' . $i ]           = $item_amount;
99
-                $paypal_args['discount_amount_' . $i ]  = $item['discount'];
95
+                $paypal_args['item_number_' . $i]      = $item['id'];
96
+                $paypal_args['item_name_' . $i]        = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8'));
97
+                $paypal_args['quantity_' . $i]         = $item['quantity'];
98
+                $paypal_args['amount_' . $i]           = $item_amount;
99
+                $paypal_args['discount_amount_' . $i]  = $item['discount'];
100 100
 
101 101
                 $i++;
102 102
             }
103 103
         }
104 104
 
105 105
         // Add taxes to the cart
106
-        if ( wpinv_use_taxes() ) {
107
-            $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax() );
106
+        if (wpinv_use_taxes()) {
107
+            $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax());
108 108
         }
109 109
 
110
-        $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice );
110
+        $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice);
111 111
 
112 112
         // Build query
113
-        $paypal_redirect .= http_build_query( $paypal_args );
113
+        $paypal_redirect .= http_build_query($paypal_args);
114 114
 
115 115
         // Fix for some sites that encode the entities
116
-        $paypal_redirect = str_replace( '&amp;', '&', $paypal_redirect );
116
+        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
117 117
 
118 118
         // Get rid of cart contents
119 119
         wpinv_empty_cart();
120 120
         
121 121
         // Redirect to PayPal
122
-        wp_redirect( $paypal_redirect );
122
+        wp_redirect($paypal_redirect);
123 123
         exit;
124 124
     }
125 125
 }
126
-add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' );
126
+add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment');
127 127
 
128
-function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) {
129
-    if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) {
130
-        $item   = new WPInv_Item( $item_id );
128
+function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) {
129
+    if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) {
130
+        $item = new WPInv_Item($item_id);
131 131
         
132
-        if ( empty( $item ) ) {
132
+        if (empty($item)) {
133 133
             return $paypal_args;
134 134
         }
135 135
 
@@ -137,24 +137,24 @@  discard block
 block discarded – undo
137 137
         $interval           = $item->get_recurring_interval();
138 138
         $bill_times         = (int)$item->get_recurring_limit();
139 139
         
140
-        $initial_amount     = wpinv_format_amount( $invoice->get_total() );
141
-        $recurring_amount   = wpinv_format_amount( $invoice->get_recurring_details( 'total' ) );
140
+        $initial_amount     = wpinv_format_amount($invoice->get_total());
141
+        $recurring_amount   = wpinv_format_amount($invoice->get_recurring_details('total'));
142 142
         
143 143
         $paypal_args['cmd'] = '_xclick-subscriptions';
144 144
         $paypal_args['sra'] = '1';
145 145
         $paypal_args['src'] = '1';
146 146
         
147 147
         // Set item description
148
-        $paypal_args['item_name']   = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( array( 'id' => $item->ID ) ), ENT_COMPAT, 'UTF-8' ) );
148
+        $paypal_args['item_name'] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name(array('id' => $item->ID)), ENT_COMPAT, 'UTF-8'));
149 149
         
150
-        if ( $invoice->is_free_trial() && $item->has_free_trial() ) {
150
+        if ($invoice->is_free_trial() && $item->has_free_trial()) {
151 151
             $paypal_args['a1']  = $initial_amount;
152 152
             $paypal_args['p1']  = $item->get_trial_interval();
153 153
             $paypal_args['t1']  = $item->get_trial_period();
154 154
             
155 155
             // Set the recurring amount
156 156
             $paypal_args['a3']  = $recurring_amount;
157
-        } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) {
157
+        } else if ($initial_amount != $recurring_amount && $bill_times != 1) {
158 158
             $paypal_args['a1']  = $initial_amount;
159 159
             $paypal_args['p1']  = $interval;
160 160
             $paypal_args['t1']  = $period;
@@ -162,63 +162,63 @@  discard block
 block discarded – undo
162 162
             // Set the recurring amount
163 163
             $paypal_args['a3']  = $recurring_amount;
164 164
             
165
-            if ( $bill_times > 1 ) {
165
+            if ($bill_times > 1) {
166 166
                 $bill_times--;
167 167
             }
168 168
         } else {
169
-            $paypal_args['a3']  = $initial_amount;
169
+            $paypal_args['a3'] = $initial_amount;
170 170
         }
171 171
         
172 172
         $paypal_args['p3']  = $interval;
173 173
         $paypal_args['t3']  = $period;
174 174
         
175
-        if ( $bill_times > 1 ) {
175
+        if ($bill_times > 1) {
176 176
             // Make sure it's not over the max of 52
177
-            $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
177
+            $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
178 178
         }
179 179
                 
180 180
         // Remove cart items
181 181
         $i = 1;
182
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
183
-            foreach ( $purchase_data['cart_details'] as $item ) {                
184
-                if ( isset( $paypal_args['item_number_' . $i] ) ) {
185
-                    unset( $paypal_args['item_number_' . $i] );
182
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
183
+            foreach ($purchase_data['cart_details'] as $item) {                
184
+                if (isset($paypal_args['item_number_' . $i])) {
185
+                    unset($paypal_args['item_number_' . $i]);
186 186
                 }
187
-                if ( isset( $paypal_args['item_name_' . $i] ) ) {
188
-                    unset( $paypal_args['item_name_' . $i] );
187
+                if (isset($paypal_args['item_name_' . $i])) {
188
+                    unset($paypal_args['item_name_' . $i]);
189 189
                 }
190
-                if ( isset( $paypal_args['quantity_' . $i] ) ) {
191
-                    unset( $paypal_args['quantity_' . $i] );
190
+                if (isset($paypal_args['quantity_' . $i])) {
191
+                    unset($paypal_args['quantity_' . $i]);
192 192
                 }
193
-                if ( isset( $paypal_args['amount_' . $i] ) ) {
194
-                    unset( $paypal_args['amount_' . $i] );
193
+                if (isset($paypal_args['amount_' . $i])) {
194
+                    unset($paypal_args['amount_' . $i]);
195 195
                 }
196
-                if ( isset( $paypal_args['discount_amount_' . $i] ) ) {
197
-                    unset( $paypal_args['discount_amount_' . $i] );
196
+                if (isset($paypal_args['discount_amount_' . $i])) {
197
+                    unset($paypal_args['discount_amount_' . $i]);
198 198
                 }
199 199
 
200 200
                 $i++;
201 201
             }
202 202
         }
203 203
         
204
-        if ( isset( $paypal_args['tax_cart'] ) ) {
205
-            unset( $paypal_args['tax_cart'] );
204
+        if (isset($paypal_args['tax_cart'])) {
205
+            unset($paypal_args['tax_cart']);
206 206
         }
207 207
                 
208
-        if ( isset( $paypal_args['upload'] ) ) {
209
-            unset( $paypal_args['upload'] );
208
+        if (isset($paypal_args['upload'])) {
209
+            unset($paypal_args['upload']);
210 210
         }
211 211
         
212
-        $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice );
212
+        $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice);
213 213
     }
214 214
     
215 215
     return $paypal_args;
216 216
 }
217
-add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 );
217
+add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3);
218 218
 
219 219
 function wpinv_process_paypal_ipn() {
220 220
 	// Check the request method is POST
221
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
221
+	if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
222 222
 		return;
223 223
 	}
224 224
 
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
 	$post_data = '';
227 227
 
228 228
 	// Fallback just in case post_max_size is lower than needed
229
-	if ( ini_get( 'allow_url_fopen' ) ) {
230
-		$post_data = file_get_contents( 'php://input' );
229
+	if (ini_get('allow_url_fopen')) {
230
+		$post_data = file_get_contents('php://input');
231 231
 	} else {
232 232
 		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
233
-		ini_set( 'post_max_size', '12M' );
233
+		ini_set('post_max_size', '12M');
234 234
 	}
235 235
 	// Start the encoded data collection with notification command
236 236
 	$encoded_data = 'cmd=_notify-validate';
@@ -239,43 +239,43 @@  discard block
 block discarded – undo
239 239
 	$arg_separator = wpinv_get_php_arg_separator_output();
240 240
 
241 241
 	// Verify there is a post_data
242
-	if ( $post_data || strlen( $post_data ) > 0 ) {
242
+	if ($post_data || strlen($post_data) > 0) {
243 243
 		// Append the data
244
-		$encoded_data .= $arg_separator.$post_data;
244
+		$encoded_data .= $arg_separator . $post_data;
245 245
 	} else {
246 246
 		// Check if POST is empty
247
-		if ( empty( $_POST ) ) {
247
+		if (empty($_POST)) {
248 248
 			// Nothing to do
249 249
 			return;
250 250
 		} else {
251 251
 			// Loop through each POST
252
-			foreach ( $_POST as $key => $value ) {
252
+			foreach ($_POST as $key => $value) {
253 253
 				// Encode the value and append the data
254
-				$encoded_data .= $arg_separator."$key=" . urlencode( $value );
254
+				$encoded_data .= $arg_separator . "$key=" . urlencode($value);
255 255
 			}
256 256
 		}
257 257
 	}
258 258
 
259 259
 	// Convert collected post data to an array
260
-	parse_str( $encoded_data, $encoded_data_array );
260
+	parse_str($encoded_data, $encoded_data_array);
261 261
 
262
-	foreach ( $encoded_data_array as $key => $value ) {
263
-		if ( false !== strpos( $key, 'amp;' ) ) {
264
-			$new_key = str_replace( '&amp;', '&', $key );
265
-			$new_key = str_replace( 'amp;', '&' , $new_key );
262
+	foreach ($encoded_data_array as $key => $value) {
263
+		if (false !== strpos($key, 'amp;')) {
264
+			$new_key = str_replace('&amp;', '&', $key);
265
+			$new_key = str_replace('amp;', '&', $new_key);
266 266
 
267
-			unset( $encoded_data_array[ $key ] );
268
-			$encoded_data_array[ $new_key ] = $value;
267
+			unset($encoded_data_array[$key]);
268
+			$encoded_data_array[$new_key] = $value;
269 269
 		}
270 270
 	}
271 271
 
272 272
 	// Get the PayPal redirect uri
273
-	$paypal_redirect = wpinv_get_paypal_redirect( true );
273
+	$paypal_redirect = wpinv_get_paypal_redirect(true);
274 274
 
275
-	if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
275
+	if (!wpinv_get_option('disable_paypal_verification', false)) {
276 276
 		// Validate the IPN
277 277
 
278
-		$remote_post_vars      = array(
278
+		$remote_post_vars = array(
279 279
 			'method'           => 'POST',
280 280
 			'timeout'          => 45,
281 281
 			'redirection'      => 5,
@@ -293,21 +293,21 @@  discard block
 block discarded – undo
293 293
 		);
294 294
 
295 295
 		// Get response
296
-		$api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
296
+		$api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars);
297 297
 
298
-		if ( is_wp_error( $api_response ) ) {
299
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
298
+		if (is_wp_error($api_response)) {
299
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
300 300
 			return; // Something went wrong
301 301
 		}
302 302
 
303
-		if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
304
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
303
+		if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) {
304
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
305 305
 			return; // Response not okay
306 306
 		}
307 307
 	}
308 308
 
309 309
 	// Check if $post_data_array has been populated
310
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
310
+	if (!is_array($encoded_data_array) && !empty($encoded_data_array))
311 311
 		return;
312 312
 
313 313
 	$defaults = array(
@@ -315,215 +315,215 @@  discard block
 block discarded – undo
315 315
 		'payment_status' => ''
316 316
 	);
317 317
 
318
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
318
+	$encoded_data_array = wp_parse_args($encoded_data_array, $defaults);
319 319
 
320
-	$invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
320
+	$invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0;
321 321
     
322
-	wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
322
+	wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__);
323 323
 
324
-	if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
324
+	if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) {
325 325
 		// Allow PayPal IPN types to be processed separately
326
-		do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
326
+		do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id);
327 327
 	} else {
328 328
 		// Fallback to web accept just in case the txn_type isn't present
329
-		do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
329
+		do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id);
330 330
 	}
331 331
 	exit;
332 332
 }
333
-add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' );
333
+add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn');
334 334
 
335
-function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) {
336
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
335
+function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) {
336
+	if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') {
337 337
 		return;
338 338
 	}
339 339
 
340
-	if( empty( $invoice_id ) ) {
340
+	if (empty($invoice_id)) {
341 341
 		return;
342 342
 	}
343 343
 
344 344
 	// Collect payment details
345
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
345
+	$purchase_key   = isset($data['invoice']) ? $data['invoice'] : $data['item_number'];
346 346
 	$paypal_amount  = $data['mc_gross'];
347
-	$payment_status = strtolower( $data['payment_status'] );
348
-	$currency_code  = strtolower( $data['mc_currency'] );
349
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
350
-	$payment_meta   = wpinv_get_invoice_meta( $invoice_id, '_wpinv_payment_meta', false );
347
+	$payment_status = strtolower($data['payment_status']);
348
+	$currency_code  = strtolower($data['mc_currency']);
349
+	$business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']);
350
+	$payment_meta   = wpinv_get_invoice_meta($invoice_id, '_wpinv_payment_meta', false);
351 351
 
352
-	if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
352
+	if (wpinv_get_payment_gateway($invoice_id) != 'paypal') {
353 353
 		return; // this isn't a PayPal standard IPN
354 354
 	}
355 355
 
356 356
 	// Verify payment recipient
357
-	if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
358
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
359
-		wpinv_update_payment_status( $invoice_id, 'failed' );
360
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) );
357
+	if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) {
358
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
359
+		wpinv_update_payment_status($invoice_id, 'failed');
360
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing'));
361 361
 		return;
362 362
 	}
363 363
 
364 364
 	// Verify payment currency
365
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
366
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
367
-		wpinv_update_payment_status( $invoice_id, 'failed' );
368
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) );
365
+	if ($currency_code != strtolower($payment_meta['currency'])) {
366
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
367
+		wpinv_update_payment_status($invoice_id, 'failed');
368
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing'));
369 369
 		return;
370 370
 	}
371 371
 
372
-	if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
372
+	if (!wpinv_get_payment_user_email($invoice_id)) {
373 373
 		// This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
374 374
 		// No email associated with purchase, so store from PayPal
375
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
375
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']);
376 376
 
377 377
 		// Setup and store the customer's details
378 378
 		$user_info = array(
379 379
 			'user_id'    => '-1',
380
-			'email'      => sanitize_text_field( $data['payer_email'] ),
381
-			'first_name' => sanitize_text_field( $data['first_name'] ),
382
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
380
+			'email'      => sanitize_text_field($data['payer_email']),
381
+			'first_name' => sanitize_text_field($data['first_name']),
382
+			'last_name'  => sanitize_text_field($data['last_name']),
383 383
 			'discount'   => '',
384 384
 		);
385
-		$user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
386
-		$user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
387
-		$user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
388
-		$user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
389
-		$user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
385
+		$user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false;
386
+		$user_info['city']    = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false;
387
+		$user_info['state']   = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false;
388
+		$user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false;
389
+		$user_info['zip']     = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false;
390 390
 
391 391
 		$payment_meta['user_info'] = $user_info;
392
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
392
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta);
393 393
 	}
394 394
 
395
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
395
+	if ($payment_status == 'refunded' || $payment_status == 'reversed') {
396 396
 		// Process a refund
397
-		wpinv_process_paypal_refund( $data, $invoice_id );
397
+		wpinv_process_paypal_refund($data, $invoice_id);
398 398
 	} else {
399
-		if ( get_post_status( $invoice_id ) == 'publish' ) {
399
+		if (get_post_status($invoice_id) == 'publish') {
400 400
 			return; // Only paid payments once
401 401
 		}
402 402
 
403 403
 		// Retrieve the total purchase amount (before PayPal)
404
-		$payment_amount = wpinv_payment_total( $invoice_id );
404
+		$payment_amount = wpinv_payment_total($invoice_id);
405 405
 
406
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
406
+		if (number_format((float)$paypal_amount, 2) < number_format((float)$payment_amount, 2)) {
407 407
 			// The prices don't match
408
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
409
-			wpinv_update_payment_status( $invoice_id, 'failed' );
410
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) );
408
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
409
+			wpinv_update_payment_status($invoice_id, 'failed');
410
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing'));
411 411
 			return;
412 412
 		}
413
-		if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
413
+		if ($purchase_key != wpinv_get_payment_key($invoice_id)) {
414 414
 			// Purchase keys don't match
415
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
416
-			wpinv_update_payment_status( $invoice_id, 'failed' );
417
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) );
415
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
416
+			wpinv_update_payment_status($invoice_id, 'failed');
417
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing'));
418 418
 			return;
419 419
 		}
420 420
 
421
-		if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
422
-			wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) );
423
-			wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
424
-			wpinv_update_payment_status( $invoice_id, 'publish' );
425
-		} else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
421
+		if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) {
422
+			wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id']));
423
+			wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']);
424
+			wpinv_update_payment_status($invoice_id, 'publish');
425
+		} else if ('pending' == $payment_status && isset($data['pending_reason'])) {
426 426
 			// Look for possible pending reasons, such as an echeck
427 427
 			$note = '';
428 428
 
429
-			switch( strtolower( $data['pending_reason'] ) ) {
429
+			switch (strtolower($data['pending_reason'])) {
430 430
 				case 'echeck' :
431
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
431
+					$note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing');
432 432
 					break;
433 433
 				
434 434
                 case 'address' :
435
-					$note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
435
+					$note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing');
436 436
 					break;
437 437
 				
438 438
                 case 'intl' :
439
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
439
+					$note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing');
440 440
 					break;
441 441
 				
442 442
                 case 'multi-currency' :
443
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
443
+					$note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing');
444 444
 					break;
445 445
 				
446 446
                 case 'paymentreview' :
447 447
                 case 'regulatory_review' :
448
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
448
+					$note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing');
449 449
 					break;
450 450
 				
451 451
                 case 'unilateral' :
452
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
452
+					$note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing');
453 453
 					break;
454 454
 				
455 455
                 case 'upgrade' :
456
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
456
+					$note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing');
457 457
 					break;
458 458
 				
459 459
                 case 'verify' :
460
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
460
+					$note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing');
461 461
 					break;
462 462
 
463 463
 				case 'other' :
464
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
464
+					$note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing');
465 465
 					break;
466 466
 			}
467 467
 
468
-			if ( ! empty( $note ) ) {
469
-				wpinv_insert_payment_note( $invoice_id, $note );
468
+			if (!empty($note)) {
469
+				wpinv_insert_payment_note($invoice_id, $note);
470 470
 			}
471 471
 		} else {
472
-			wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) );
472
+			wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status));
473 473
 		}
474 474
 	}
475 475
 }
476
-add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 );
476
+add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2);
477 477
 
478 478
 // Process PayPal subscription sign ups
479
-add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' );
479
+add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup');
480 480
 
481 481
 // Process PayPal subscription payments
482
-add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' );
482
+add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment');
483 483
 
484 484
 // Process PayPal subscription cancellations
485
-add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' );
485
+add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel');
486 486
 
487 487
 // Process PayPal subscription end of term notices
488
-add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' );
488
+add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot');
489 489
 
490 490
 // Process PayPal payment failed
491
-add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' );
491
+add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed');
492 492
 
493 493
 
494 494
 /**
495 495
  * Process the subscription started IPN.
496 496
  */
497
-function wpinv_process_paypal_subscr_signup( $ipn_data ) {
498
-    $parent_invoice_id = absint( $ipn_data['custom'] );
499
-    if( empty( $parent_invoice_id ) ) {
497
+function wpinv_process_paypal_subscr_signup($ipn_data) {
498
+    $parent_invoice_id = absint($ipn_data['custom']);
499
+    if (empty($parent_invoice_id)) {
500 500
         return;
501 501
     }
502 502
 
503
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
504
-    if ( empty( $invoice ) ) {
503
+    $invoice = wpinv_get_invoice($parent_invoice_id);
504
+    if (empty($invoice)) {
505 505
         return;
506 506
     }
507 507
 
508
-    if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) {
509
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ) );
510
-        wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['invoice'] );
508
+    if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) {
509
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice']));
510
+        wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['invoice']);
511 511
     }
512 512
     
513
-    wpinv_update_payment_status( $parent_invoice_id, 'publish' );
513
+    wpinv_update_payment_status($parent_invoice_id, 'publish');
514 514
     sleep(1);
515
-    wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ) );
515
+    wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']));
516 516
     
517
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
518
-    if ( false === $subscription ) {
517
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
518
+    if (false === $subscription) {
519 519
         return;
520 520
     }
521 521
 
522
-    $cart_details   = $invoice->cart_details;
522
+    $cart_details = $invoice->cart_details;
523 523
 
524
-    if ( !empty( $cart_details ) ) {
525
-        foreach ( $cart_details as $cart_item ) {
526
-            $item = new WPInv_Item( $cart_item['id'] );
524
+    if (!empty($cart_details)) {
525
+        foreach ($cart_details as $cart_item) {
526
+            $item = new WPInv_Item($cart_item['id']);
527 527
             
528 528
             $status = $invoice->is_free_trial() && $item->has_free_trial() ? 'trialing' : 'active';
529 529
             
@@ -532,15 +532,15 @@  discard block
 block discarded – undo
532 532
                 'status'            => $status,
533 533
                 'period'            => $item->get_recurring_period(),
534 534
                 'initial_amount'    => $invoice->get_total(),
535
-                'recurring_amount'  => $invoice->get_recurring_details( 'total' ),
535
+                'recurring_amount'  => $invoice->get_recurring_details('total'),
536 536
                 'interval'          => $item->get_recurring_interval(),
537 537
                 'bill_times'        => $item->get_recurring_limit(),
538
-                'expiration'        => $invoice->get_new_expiration( $cart_item['id'] ),
538
+                'expiration'        => $invoice->get_new_expiration($cart_item['id']),
539 539
                 'profile_id'        => $ipn_data['subscr_id'],
540
-                'created'           => date_i18n( 'Y-m-d H:i:s', strtotime( $ipn_data['subscr_date'] ) )
540
+                'created'           => date_i18n('Y-m-d H:i:s', strtotime($ipn_data['subscr_date']))
541 541
             );
542 542
             
543
-            if ( $item->has_free_trial() ) {
543
+            if ($item->has_free_trial()) {
544 544
                 $args['trial_period']      = $item->get_trial_period();
545 545
                 $args['trial_interval']    = $item->get_trial_interval();
546 546
             } else {
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
             }
550 550
             
551 551
 
552
-            $subscription->update_subscription( $args );
552
+            $subscription->update_subscription($args);
553 553
         }
554 554
     }
555 555
 }
@@ -557,39 +557,39 @@  discard block
 block discarded – undo
557 557
 /**
558 558
  * Process the subscription payment received IPN.
559 559
  */
560
-function wpinv_process_paypal_subscr_payment( $ipn_data ) {
561
-    $parent_invoice_id = absint( $ipn_data['custom'] );
560
+function wpinv_process_paypal_subscr_payment($ipn_data) {
561
+    $parent_invoice_id = absint($ipn_data['custom']);
562 562
     
563
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
564
-    if ( false === $subscription ) {
563
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
564
+    if (false === $subscription) {
565 565
         return;
566 566
     }
567 567
     
568
-    $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id );
569
-    $signup_date    = strtotime( $subscription->get_subscription_created() );
570
-    $today          = date_i18n( 'Y-m-d', $signup_date ) == date_i18n( 'Y-m-d', strtotime( $ipn_data['payment_date'] ) );
568
+    $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id);
569
+    $signup_date    = strtotime($subscription->get_subscription_created());
570
+    $today          = date_i18n('Y-m-d', $signup_date) == date_i18n('Y-m-d', strtotime($ipn_data['payment_date']));
571 571
 
572 572
     // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet.
573
-    if ( $today && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) {
574
-        wpinv_update_payment_status( $parent_invoice_id, 'publish' );
573
+    if ($today && (!$transaction_id || $transaction_id == $parent_invoice_id)) {
574
+        wpinv_update_payment_status($parent_invoice_id, 'publish');
575 575
         sleep(1);
576 576
         
577 577
         // This is the very first payment
578
-        wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] );
579
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) );
578
+        wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']);
579
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']));
580 580
         return;
581 581
     }
582 582
     
583
-    if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) {
583
+    if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) {
584 584
         return; // Payment already recorded
585 585
     }
586 586
 
587
-    $currency_code = strtolower( $ipn_data['mc_currency'] );
587
+    $currency_code = strtolower($ipn_data['mc_currency']);
588 588
 
589 589
     // verify details
590
-    if ( $currency_code != strtolower( wpinv_get_currency() ) ) {
590
+    if ($currency_code != strtolower(wpinv_get_currency())) {
591 591
         // the currency code is invalid
592
-        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) );
592
+        wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data)));
593 593
         return;
594 594
     }
595 595
 
@@ -598,11 +598,11 @@  discard block
 block discarded – undo
598 598
         'transaction_id' => $ipn_data['txn_id']
599 599
     );
600 600
     
601
-    $invoice = wpinv_recurring_add_subscription_payment( $parent_invoice_id, $args );
601
+    $invoice = wpinv_recurring_add_subscription_payment($parent_invoice_id, $args);
602 602
     
603
-    if ( !empty( $invoice ) ) {
603
+    if (!empty($invoice)) {
604 604
         sleep(1);
605
-        wpinv_insert_payment_note( $invoice->ID, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) );
605
+        wpinv_insert_payment_note($invoice->ID, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']));
606 606
 
607 607
         $invoice->renew_subscription();
608 608
     }
@@ -611,10 +611,10 @@  discard block
 block discarded – undo
611 611
 /**
612 612
  * Process the subscription canceled IPN.
613 613
  */
614
-function wpinv_process_paypal_subscr_cancel( $ipn_data ) {
615
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
614
+function wpinv_process_paypal_subscr_cancel($ipn_data) {
615
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
616 616
 
617
-    if( false === $subscription ) {
617
+    if (false === $subscription) {
618 618
         return;
619 619
     }
620 620
 
@@ -624,10 +624,10 @@  discard block
 block discarded – undo
624 624
 /**
625 625
  * Process the subscription expired IPN.
626 626
  */
627
-function wpinv_process_paypal_subscr_eot( $ipn_data ) {
628
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
627
+function wpinv_process_paypal_subscr_eot($ipn_data) {
628
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
629 629
 
630
-    if( false === $subscription ) {
630
+    if (false === $subscription) {
631 631
         return;
632 632
     }
633 633
 
@@ -637,45 +637,45 @@  discard block
 block discarded – undo
637 637
 /**
638 638
  * Process the subscription payment failed IPN.
639 639
  */
640
-function wpinv_process_paypal_subscr_failed( $ipn_data ) {
641
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
640
+function wpinv_process_paypal_subscr_failed($ipn_data) {
641
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
642 642
 
643
-    if( false === $subscription ) {
643
+    if (false === $subscription) {
644 644
         return;
645 645
     }
646 646
 
647 647
     $subscription->failing_subscription();
648 648
 
649
-    do_action( 'wpinv_recurring_payment_failed', $subscription );
649
+    do_action('wpinv_recurring_payment_failed', $subscription);
650 650
 }
651 651
 
652 652
 /**
653 653
  * Retrieve the subscription this IPN notice is for.
654 654
  */
655
-function wpinv_get_paypal_subscription( $ipn_data = array() ) {
656
-    $parent_invoice_id = absint( $ipn_data['custom'] );
655
+function wpinv_get_paypal_subscription($ipn_data = array()) {
656
+    $parent_invoice_id = absint($ipn_data['custom']);
657 657
 
658
-    if( empty( $parent_invoice_id ) ) {
658
+    if (empty($parent_invoice_id)) {
659 659
         return false;
660 660
     }
661 661
 
662
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
663
-    if ( empty( $invoice ) ) {
662
+    $invoice = wpinv_get_invoice($parent_invoice_id);
663
+    if (empty($invoice)) {
664 664
         return false;
665 665
     }
666 666
 
667
-    $subscription = wpinv_get_subscription( $ipn_data['subscr_id'], true );
667
+    $subscription = wpinv_get_subscription($ipn_data['subscr_id'], true);
668 668
 
669
-    if ( empty( $subscription ) ) {
670
-        $subs         = wpinv_get_subscriptions( array( 'parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1 ) );
671
-        $subscription = reset( $subs );
669
+    if (empty($subscription)) {
670
+        $subs         = wpinv_get_subscriptions(array('parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1));
671
+        $subscription = reset($subs);
672 672
 
673
-        if ( $subscription && $subscription->ID > 0 ) {
673
+        if ($subscription && $subscription->ID > 0) {
674 674
             // Update the profile ID so it is set for future renewals
675
-            $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) );
675
+            $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id'])));
676 676
         } else {
677 677
             $subscription = $invoice;
678
-            $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) );
678
+            $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id'])));
679 679
             // No subscription found with a matching payment ID, bail
680 680
             //return false;
681 681
         }
@@ -685,39 +685,39 @@  discard block
 block discarded – undo
685 685
 
686 686
 }
687 687
 
688
-function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
688
+function wpinv_process_paypal_refund($data, $invoice_id = 0) {
689 689
 	// Collect payment details
690 690
 
691
-	if( empty( $invoice_id ) ) {
691
+	if (empty($invoice_id)) {
692 692
 		return;
693 693
 	}
694 694
 
695
-	if ( get_post_status( $invoice_id ) == 'refunded' ) {
695
+	if (get_post_status($invoice_id) == 'refunded') {
696 696
 		return; // Only refund payments once
697 697
 	}
698 698
 
699
-	$payment_amount = wpinv_payment_total( $invoice_id );
699
+	$payment_amount = wpinv_payment_total($invoice_id);
700 700
 	$refund_amount  = $data['mc_gross'] * -1;
701 701
 
702
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
703
-		wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) );
702
+	if (number_format((float)$refund_amount, 2) < number_format((float)$payment_amount, 2)) {
703
+		wpinv_insert_payment_note($invoice_id, sprintf(__('Partial PayPal refund processed: %s', 'invoicing'), $data['parent_txn_id']));
704 704
 		return; // This is a partial refund
705 705
 	}
706 706
 
707
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) );
708
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) );
709
-	wpinv_update_payment_status( $invoice_id, 'refunded' );
707
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code']));
708
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id']));
709
+	wpinv_update_payment_status($invoice_id, 'refunded');
710 710
 }
711 711
 
712
-function wpinv_get_paypal_redirect( $ssl_check = false ) {
713
-    if ( is_ssl() || ! $ssl_check ) {
712
+function wpinv_get_paypal_redirect($ssl_check = false) {
713
+    if (is_ssl() || !$ssl_check) {
714 714
         $protocol = 'https://';
715 715
     } else {
716 716
         $protocol = 'http://';
717 717
     }
718 718
 
719 719
     // Check the current payment mode
720
-    if ( wpinv_is_test_mode( 'paypal' ) ) {
720
+    if (wpinv_is_test_mode('paypal')) {
721 721
         // Test mode
722 722
         $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr';
723 723
     } else {
@@ -725,67 +725,67 @@  discard block
 block discarded – undo
725 725
         $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr';
726 726
     }
727 727
 
728
-    return apply_filters( 'wpinv_paypal_uri', $paypal_uri );
728
+    return apply_filters('wpinv_paypal_uri', $paypal_uri);
729 729
 }
730 730
 
731
-function wpinv_paypal_success_page_content( $content ) {
731
+function wpinv_paypal_success_page_content($content) {
732 732
     global $wpi_invoice;
733 733
     
734 734
     $session = wpinv_get_checkout_session();
735 735
 
736
-    if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] )  ) {
736
+    if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) {
737 737
         return $content;
738 738
     }
739 739
 
740
-    $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] );
740
+    $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']);
741 741
 
742
-    if ( empty(  $invoice_id ) ) {
742
+    if (empty($invoice_id)) {
743 743
         return $content;
744 744
     }
745 745
 
746
-    $wpi_invoice = wpinv_get_invoice( $invoice_id );
746
+    $wpi_invoice = wpinv_get_invoice($invoice_id);
747 747
     
748
-    if ( !empty( $wpi_invoice ) && 'pending' == $wpi_invoice->status ) {
748
+    if (!empty($wpi_invoice) && 'pending' == $wpi_invoice->status) {
749 749
         // Payment is still pending so show processing indicator to fix the Race Condition, issue #
750 750
         ob_start();
751
-        wpinv_get_template_part( 'wpinv-payment-processing' );
751
+        wpinv_get_template_part('wpinv-payment-processing');
752 752
         $content = ob_get_clean();
753 753
     }
754 754
 
755 755
     return $content;
756 756
 }
757
-add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' );
757
+add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content');
758 758
 
759
-function wpinv_paypal_get_transaction_id( $invoice_id ) {
759
+function wpinv_paypal_get_transaction_id($invoice_id) {
760 760
     $transaction_id = '';
761
-    $notes = wpinv_get_invoice_notes( $invoice_id );
761
+    $notes = wpinv_get_invoice_notes($invoice_id);
762 762
 
763
-    foreach ( $notes as $note ) {
764
-        if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) {
763
+    foreach ($notes as $note) {
764
+        if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) {
765 765
             $transaction_id = $match[1];
766 766
             continue;
767 767
         }
768 768
     }
769 769
 
770
-    return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id );
770
+    return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id);
771 771
 }
772
-add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 );
772
+add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1);
773 773
 
774
-function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
775
-    if ( $invoice->is_free_trial() || $transaction_id == $invoice_id ) { // Free trial does not have transaction at PayPal.
774
+function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) {
775
+    if ($invoice->is_free_trial() || $transaction_id == $invoice_id) { // Free trial does not have transaction at PayPal.
776 776
         $transaction_url = $invoice->get_view_url();
777 777
     } else {
778
-        $sandbox = wpinv_is_test_mode( 'paypal' ) ? '.sandbox' : '';
778
+        $sandbox = wpinv_is_test_mode('paypal') ? '.sandbox' : '';
779 779
         $transaction_url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=' . $transaction_id;
780 780
     }
781 781
 
782
-    $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>';
782
+    $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>';
783 783
 
784
-    return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice );
784
+    return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice);
785 785
 }
786
-add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 );
786
+add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3);
787 787
 
788 788
 function wpinv_gateway_paypal_button_label($label) {
789
-    return __( 'Proceed to PayPal', 'invoicing' );
789
+    return __('Proceed to PayPal', 'invoicing');
790 790
 }
791
-add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 );
792 791
\ No newline at end of file
792
+add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1);
793 793
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Spacing   +780 added lines, -780 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  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
 final class WPInv_Invoice {
15
-    public $ID  = 0;
15
+    public $ID = 0;
16 16
     public $title;
17 17
     
18 18
     public $pending;
@@ -64,17 +64,17 @@  discard block
 block discarded – undo
64 64
     public $full_name = '';
65 65
     public $parent_invoice = 0;
66 66
     
67
-    public function __construct( $invoice_id = false ) {
68
-        if( empty( $invoice_id ) ) {
67
+    public function __construct($invoice_id = false) {
68
+        if (empty($invoice_id)) {
69 69
             return false;
70 70
         }
71 71
 
72
-        $this->setup_invoice( $invoice_id );
72
+        $this->setup_invoice($invoice_id);
73 73
     }
74 74
 
75
-    public function get( $key ) {
76
-        if ( method_exists( $this, 'get_' . $key ) ) {
77
-            $value = call_user_func( array( $this, 'get_' . $key ) );
75
+    public function get($key) {
76
+        if (method_exists($this, 'get_' . $key)) {
77
+            $value = call_user_func(array($this, 'get_' . $key));
78 78
         } else {
79 79
             $value = $this->$key;
80 80
         }
@@ -82,54 +82,54 @@  discard block
 block discarded – undo
82 82
         return $value;
83 83
     }
84 84
 
85
-    public function set( $key, $value ) {
86
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
85
+    public function set($key, $value) {
86
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
87 87
 
88
-        if ( $key === 'status' ) {
88
+        if ($key === 'status') {
89 89
             $this->old_status = $this->status;
90 90
         }
91 91
 
92
-        if ( ! in_array( $key, $ignore ) ) {
93
-            $this->pending[ $key ] = $value;
92
+        if (!in_array($key, $ignore)) {
93
+            $this->pending[$key] = $value;
94 94
         }
95 95
 
96
-        if( '_ID' !== $key ) {
96
+        if ('_ID' !== $key) {
97 97
             $this->$key = $value;
98 98
         }
99 99
     }
100 100
 
101
-    public function _isset( $name ) {
102
-        if ( property_exists( $this, $name) ) {
103
-            return false === empty( $this->$name );
101
+    public function _isset($name) {
102
+        if (property_exists($this, $name)) {
103
+            return false === empty($this->$name);
104 104
         } else {
105 105
             return null;
106 106
         }
107 107
     }
108 108
 
109
-    private function setup_invoice( $invoice_id ) {
109
+    private function setup_invoice($invoice_id) {
110 110
         $this->pending = array();
111 111
 
112
-        if ( empty( $invoice_id ) ) {
112
+        if (empty($invoice_id)) {
113 113
             return false;
114 114
         }
115 115
 
116
-        $invoice = get_post( $invoice_id );
116
+        $invoice = get_post($invoice_id);
117 117
 
118
-        if( !$invoice || is_wp_error( $invoice ) ) {
118
+        if (!$invoice || is_wp_error($invoice)) {
119 119
             return false;
120 120
         }
121 121
 
122
-        if( 'wpi_invoice' !== $invoice->post_type ) {
122
+        if ('wpi_invoice' !== $invoice->post_type) {
123 123
             return false;
124 124
         }
125 125
 
126
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
126
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
127 127
         
128 128
         // Primary Identifier
129
-        $this->ID              = absint( $invoice_id );
129
+        $this->ID              = absint($invoice_id);
130 130
         
131 131
         // We have a payment, get the generic payment_meta item to reduce calls to it
132
-        $this->payment_meta    = $this->get_meta( '_wpinv_payment_meta', false );
132
+        $this->payment_meta    = $this->get_meta('_wpinv_payment_meta', false);
133 133
         $this->date            = $invoice->post_date;
134 134
         $this->due_date        = $this->setup_due_date();
135 135
         $this->completed_date  = $this->setup_completed_date();
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
         $this->post_status     = $this->status;
138 138
         $this->mode            = $this->setup_mode();
139 139
         $this->parent_invoice  = $invoice->post_parent;
140
-        $this->post_name       = $this->setup_post_name( $invoice );
140
+        $this->post_name       = $this->setup_post_name($invoice);
141 141
         $this->status_nicename = $this->setup_status_nicename();
142 142
 
143 143
         // Items
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
         
160 160
         // User based
161 161
         $this->ip              = $this->setup_ip();
162
-        $this->user_id         = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();
163
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
162
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();
163
+        $this->email           = get_the_author_meta('email', $this->user_id);
164 164
         
165 165
         $this->user_info       = $this->setup_user_info();
166 166
                 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         $this->company         = $this->user_info['company'];
170 170
         $this->vat_number      = $this->user_info['vat_number'];
171 171
         $this->vat_rate        = $this->user_info['vat_rate'];
172
-        $this->adddress_confirmed  = $this->user_info['adddress_confirmed'];
172
+        $this->adddress_confirmed = $this->user_info['adddress_confirmed'];
173 173
         $this->address         = $this->user_info['address'];
174 174
         $this->city            = $this->user_info['city'];
175 175
         $this->country         = $this->user_info['country'];
@@ -184,48 +184,48 @@  discard block
 block discarded – undo
184 184
         // Other Identifiers
185 185
         $this->key             = $this->setup_invoice_key();
186 186
         $this->number          = $this->setup_invoice_number();
187
-        $this->title           = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
187
+        $this->title           = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
188 188
         
189
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
189
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
190 190
         
191 191
         // Allow extensions to add items to this object via hook
192
-        do_action( 'wpinv_setup_invoice', $this, $invoice_id );
192
+        do_action('wpinv_setup_invoice', $this, $invoice_id);
193 193
 
194 194
         return true;
195 195
     }
196 196
     
197 197
     private function setup_status_nicename() {
198
-        $all_invoice_statuses  = wpinv_get_invoice_statuses();
198
+        $all_invoice_statuses = wpinv_get_invoice_statuses();
199 199
         
200
-        $status = array_key_exists( $this->status, $all_invoice_statuses ) ? $all_invoice_statuses[$this->status] : ucfirst( $this->status );
200
+        $status = array_key_exists($this->status, $all_invoice_statuses) ? $all_invoice_statuses[$this->status] : ucfirst($this->status);
201 201
 
202 202
         return $status;
203 203
     }
204 204
     
205
-    private function setup_post_name( $post = NULL ) {
205
+    private function setup_post_name($post = NULL) {
206 206
         $post_name = '';
207 207
         
208
-        if ( !empty( $post ) ) {
209
-            if( !empty( $post->post_name ) ) {
208
+        if (!empty($post)) {
209
+            if (!empty($post->post_name)) {
210 210
                 $post_name = $post->post_name;
211
-            } else if ( !empty( $post->ID ) && !empty( $post->post_title ) ) {
212
-                $post_name = sanitize_title( $post->post_title );
211
+            } else if (!empty($post->ID) && !empty($post->post_title)) {
212
+                $post_name = sanitize_title($post->post_title);
213 213
                 
214 214
                 global $wpdb;
215
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
215
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
216 216
             }
217 217
         }
218 218
 
219
-        $this->post_name   = $post_name;
219
+        $this->post_name = $post_name;
220 220
     }
221 221
     
222 222
     private function setup_due_date() {
223
-        $due_date = $this->get_meta( '_wpinv_due_date', true );
223
+        $due_date = $this->get_meta('_wpinv_due_date', true);
224 224
         
225
-        if ( empty( $due_date ) ) {
226
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
227
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
228
-        } else if ( $due_date == 'none' ) {
225
+        if (empty($due_date)) {
226
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
227
+            $due_date = date_i18n('Y-m-d', $overdue_time);
228
+        } else if ($due_date == 'none') {
229 229
             $due_date = '';
230 230
         }
231 231
         
@@ -233,63 +233,63 @@  discard block
 block discarded – undo
233 233
     }
234 234
     
235 235
     private function setup_completed_date() {
236
-        $invoice = get_post( $this->ID );
236
+        $invoice = get_post($this->ID);
237 237
 
238
-        if ( 'pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
238
+        if ('pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
239 239
             return false; // This invoice was never paid
240 240
         }
241 241
 
242
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
242
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
243 243
 
244 244
         return $date;
245 245
     }
246 246
     
247 247
     private function setup_cart_details() {
248
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
248
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
249 249
         return $cart_details;
250 250
     }
251 251
     
252 252
     public function array_convert() {
253
-        return get_object_vars( $this );
253
+        return get_object_vars($this);
254 254
     }
255 255
     
256 256
     private function setup_items() {
257
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
257
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
258 258
         return $items;
259 259
     }
260 260
     
261 261
     private function setup_fees() {
262
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
262
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
263 263
         return $payment_fees;
264 264
     }
265 265
         
266 266
     private function setup_currency() {
267
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
267
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
268 268
         return $currency;
269 269
     }
270 270
     
271 271
     private function setup_discount() {
272 272
         //$discount = $this->get_meta( '_wpinv_discount', true );
273
-        $discount = $this->subtotal - ( $this->total - $this->tax - $this->fees_total );
274
-        if ( $discount < 0 ) {
273
+        $discount = $this->subtotal - ($this->total - $this->tax - $this->fees_total);
274
+        if ($discount < 0) {
275 275
             $discount = 0;
276 276
         }
277
-        $discount = wpinv_format_amount( $discount, NULL, true );
277
+        $discount = wpinv_format_amount($discount, NULL, true);
278 278
         
279 279
         return $discount;
280 280
     }
281 281
     
282 282
     private function setup_discount_code() {
283
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
283
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
284 284
         return $discount_code;
285 285
     }
286 286
     
287 287
     private function setup_tax() {
288
-        $tax = $this->get_meta( '_wpinv_tax', true );
288
+        $tax = $this->get_meta('_wpinv_tax', true);
289 289
 
290 290
         // We don't have tax as it's own meta and no meta was passed
291
-        if ( '' === $tax ) {            
292
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
291
+        if ('' === $tax) {            
292
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
293 293
         }
294 294
 
295 295
         return $tax;
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
         $subtotal     = 0;
304 304
         $cart_details = $this->cart_details;
305 305
 
306
-        if ( is_array( $cart_details ) ) {
307
-            foreach ( $cart_details as $item ) {
308
-                if ( isset( $item['subtotal'] ) ) {
306
+        if (is_array($cart_details)) {
307
+            foreach ($cart_details as $item) {
308
+                if (isset($item['subtotal'])) {
309 309
                     $subtotal += $item['subtotal'];
310 310
                 }
311 311
             }
@@ -319,18 +319,18 @@  discard block
 block discarded – undo
319 319
     }
320 320
     
321 321
     private function setup_discounts() {
322
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
322
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
323 323
         return $discounts;
324 324
     }
325 325
     
326 326
     private function setup_total() {
327
-        $amount = $this->get_meta( '_wpinv_total', true );
327
+        $amount = $this->get_meta('_wpinv_total', true);
328 328
 
329
-        if ( empty( $amount ) && '0.00' != $amount ) {
330
-            $meta   = $this->get_meta( '_wpinv_payment_meta', false );
331
-            $meta   = maybe_unserialize( $meta );
329
+        if (empty($amount) && '0.00' != $amount) {
330
+            $meta   = $this->get_meta('_wpinv_payment_meta', false);
331
+            $meta   = maybe_unserialize($meta);
332 332
 
333
-            if ( isset( $meta['amount'] ) ) {
333
+            if (isset($meta['amount'])) {
334 334
                 $amount = $meta['amount'];
335 335
             }
336 336
         }
@@ -339,13 +339,13 @@  discard block
 block discarded – undo
339 339
     }
340 340
     
341 341
     private function setup_mode() {
342
-        return $this->get_meta( '_wpinv_mode', true );
342
+        return $this->get_meta('_wpinv_mode', true);
343 343
     }
344 344
 
345 345
     private function setup_gateway() {
346
-        $gateway = $this->get_meta( '_wpinv_gateway', true );
346
+        $gateway = $this->get_meta('_wpinv_gateway', true);
347 347
         
348
-        if ( empty( $gateway ) && 'publish' === $this->status || 'complete' === $this->status ) {
348
+        if (empty($gateway) && 'publish' === $this->status || 'complete' === $this->status) {
349 349
             $gateway = 'manual';
350 350
         }
351 351
         
@@ -353,23 +353,23 @@  discard block
 block discarded – undo
353 353
     }
354 354
     
355 355
     private function setup_gateway_title() {
356
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
356
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
357 357
         return $gateway_title;
358 358
     }
359 359
 
360 360
     private function setup_transaction_id() {
361
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id', true );
361
+        $transaction_id = $this->get_meta('_wpinv_transaction_id', true);
362 362
 
363
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
363
+        if (empty($transaction_id) || (int)$transaction_id === (int)$this->ID) {
364 364
             $gateway        = $this->gateway;
365
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
365
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
366 366
         }
367 367
 
368 368
         return $transaction_id;
369 369
     }
370 370
 
371 371
     private function setup_ip() {
372
-        $ip = $this->get_meta( '_wpinv_user_ip', true );
372
+        $ip = $this->get_meta('_wpinv_user_ip', true);
373 373
         return $ip;
374 374
     }
375 375
 
@@ -379,62 +379,62 @@  discard block
 block discarded – undo
379 379
     ///}
380 380
         
381 381
     private function setup_first_name() {
382
-        $first_name = $this->get_meta( '_wpinv_first_name', true );
382
+        $first_name = $this->get_meta('_wpinv_first_name', true);
383 383
         return $first_name;
384 384
     }
385 385
     
386 386
     private function setup_last_name() {
387
-        $last_name = $this->get_meta( '_wpinv_last_name', true );
387
+        $last_name = $this->get_meta('_wpinv_last_name', true);
388 388
         return $last_name;
389 389
     }
390 390
     
391 391
     private function setup_company() {
392
-        $company = $this->get_meta( '_wpinv_company', true );
392
+        $company = $this->get_meta('_wpinv_company', true);
393 393
         return $company;
394 394
     }
395 395
     
396 396
     private function setup_vat_number() {
397
-        $vat_number = $this->get_meta( '_wpinv_vat_number', true );
397
+        $vat_number = $this->get_meta('_wpinv_vat_number', true);
398 398
         return $vat_number;
399 399
     }
400 400
     
401 401
     private function setup_vat_rate() {
402
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate', true );
402
+        $vat_rate = $this->get_meta('_wpinv_vat_rate', true);
403 403
         return $vat_rate;
404 404
     }
405 405
     
406 406
     private function setup_adddress_confirmed() {
407
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed', true );
407
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed', true);
408 408
         return $adddress_confirmed;
409 409
     }
410 410
     
411 411
     private function setup_phone() {
412
-        $phone = $this->get_meta( '_wpinv_phone', true );
412
+        $phone = $this->get_meta('_wpinv_phone', true);
413 413
         return $phone;
414 414
     }
415 415
     
416 416
     private function setup_address() {
417
-        $address = $this->get_meta( '_wpinv_address', true );
417
+        $address = $this->get_meta('_wpinv_address', true);
418 418
         return $address;
419 419
     }
420 420
     
421 421
     private function setup_city() {
422
-        $city = $this->get_meta( '_wpinv_city', true );
422
+        $city = $this->get_meta('_wpinv_city', true);
423 423
         return $city;
424 424
     }
425 425
     
426 426
     private function setup_country() {
427
-        $country = $this->get_meta( '_wpinv_country', true );
427
+        $country = $this->get_meta('_wpinv_country', true);
428 428
         return $country;
429 429
     }
430 430
     
431 431
     private function setup_state() {
432
-        $state = $this->get_meta( '_wpinv_state', true );
432
+        $state = $this->get_meta('_wpinv_state', true);
433 433
         return $state;
434 434
     }
435 435
     
436 436
     private function setup_zip() {
437
-        $zip = $this->get_meta( '_wpinv_zip', true );
437
+        $zip = $this->get_meta('_wpinv_zip', true);
438 438
         return $zip;
439 439
     }
440 440
 
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
             'user_id'        => $this->user_id,
444 444
             'first_name'     => $this->first_name,
445 445
             'last_name'      => $this->last_name,
446
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
446
+            'email'          => get_the_author_meta('email', $this->user_id),
447 447
             'phone'          => $this->phone,
448 448
             'address'        => $this->address,
449 449
             'city'           => $this->city,
@@ -458,12 +458,12 @@  discard block
 block discarded – undo
458 458
         );
459 459
         
460 460
         $user_info = array();
461
-        if ( isset( $this->payment_meta['user_info'] ) ) {
462
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
461
+        if (isset($this->payment_meta['user_info'])) {
462
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
463 463
             
464
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
464
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
465 465
                 $this->user_id = $post->post_author;
466
-                $this->email = get_the_author_meta( 'email', $this->user_id );
466
+                $this->email = get_the_author_meta('email', $this->user_id);
467 467
                 
468 468
                 $user_info['user_id'] = $this->user_id;
469 469
                 $user_info['email'] = $this->email;
@@ -472,13 +472,13 @@  discard block
 block discarded – undo
472 472
             }
473 473
         }
474 474
         
475
-        $user_info    = wp_parse_args( $user_info, $defaults );
475
+        $user_info = wp_parse_args($user_info, $defaults);
476 476
         
477 477
         // Get the user, but only if it's been created
478
-        $user = get_userdata( $this->user_id );
478
+        $user = get_userdata($this->user_id);
479 479
         
480
-        if ( !empty( $user ) && $user->ID > 0 ) {
481
-            if ( empty( $user_info ) ) {
480
+        if (!empty($user) && $user->ID > 0) {
481
+            if (empty($user_info)) {
482 482
                 $user_info = array(
483 483
                     'user_id'    => $user->ID,
484 484
                     'first_name' => $user->first_name,
@@ -487,23 +487,23 @@  discard block
 block discarded – undo
487 487
                     'discount'   => '',
488 488
                 );
489 489
             } else {
490
-                foreach ( $user_info as $key => $value ) {
491
-                    if ( ! empty( $value ) ) {
490
+                foreach ($user_info as $key => $value) {
491
+                    if (!empty($value)) {
492 492
                         continue;
493 493
                     }
494 494
 
495
-                    switch( $key ) {
495
+                    switch ($key) {
496 496
                         case 'user_id':
497
-                            $user_info[ $key ] = $user->ID;
497
+                            $user_info[$key] = $user->ID;
498 498
                             break;
499 499
                         case 'first_name':
500
-                            $user_info[ $key ] = $user->first_name;
500
+                            $user_info[$key] = $user->first_name;
501 501
                             break;
502 502
                         case 'last_name':
503
-                            $user_info[ $key ] = $user->last_name;
503
+                            $user_info[$key] = $user->last_name;
504 504
                             break;
505 505
                         case 'email':
506
-                            $user_info[ $key ] = $user->user_email;
506
+                            $user_info[$key] = $user->user_email;
507 507
                             break;
508 508
                     }
509 509
                 }
@@ -514,16 +514,16 @@  discard block
 block discarded – undo
514 514
     }
515 515
 
516 516
     private function setup_invoice_key() {
517
-        $key = $this->get_meta( '_wpinv_key', true );
517
+        $key = $this->get_meta('_wpinv_key', true);
518 518
         
519 519
         return $key;
520 520
     }
521 521
 
522 522
     private function setup_invoice_number() {
523
-        $number = $this->get_meta( '_wpinv_number', true );
523
+        $number = $this->get_meta('_wpinv_number', true);
524 524
 
525
-        if ( !$number ) {
526
-            $number = wpinv_format_invoice_number( $this->ID );
525
+        if (!$number) {
526
+            $number = wpinv_format_invoice_number($this->ID);
527 527
         }
528 528
 
529 529
         return $number;
@@ -534,18 +534,18 @@  discard block
 block discarded – undo
534 534
 
535 535
         if ($number = $this->get_number()) {
536 536
             $invoice_title = $number;
537
-        } else if ( ! empty( $this->ID ) ) {
538
-            $invoice_title = wpinv_format_invoice_number( $this->ID );
537
+        } else if (!empty($this->ID)) {
538
+            $invoice_title = wpinv_format_invoice_number($this->ID);
539 539
         } else {
540
-            $invoice_title = wpinv_format_invoice_number( 0 );
540
+            $invoice_title = wpinv_format_invoice_number(0);
541 541
         }
542 542
 
543
-        if ( empty( $this->key ) ) {
543
+        if (empty($this->key)) {
544 544
             $this->key = self::generate_key();
545 545
             $this->pending['key'] = $this->key;
546 546
         }
547 547
 
548
-        if ( empty( $this->ip ) ) {
548
+        if (empty($this->ip)) {
549 549
             $this->ip = wpinv_get_ip();
550 550
             $this->pending['ip'] = $this->ip;
551 551
         }
@@ -577,75 +577,75 @@  discard block
 block discarded – undo
577 577
             'fees'         => $this->fees,
578 578
         );
579 579
         
580
-        $post_name      = sanitize_title( $invoice_title );
580
+        $post_name = sanitize_title($invoice_title);
581 581
 
582 582
         $post_data = array(
583 583
                         'post_title'    => $invoice_title,
584 584
                         'post_status'   => $this->status,
585 585
                         'post_author'   => $this->user_id,
586 586
                         'post_type'     => 'wpi_invoice',
587
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
588
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
587
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
588
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
589 589
                         'post_parent'   => $this->parent_invoice,
590 590
                     );
591
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
591
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
592 592
 
593 593
         // Create a blank invoice
594
-        if ( !empty( $this->ID ) ) {
594
+        if (!empty($this->ID)) {
595 595
             $args['ID']         = $this->ID;
596 596
             $args['post_name']  = $post_name;
597 597
             
598
-            $invoice_id = wp_update_post( $args );
598
+            $invoice_id = wp_update_post($args);
599 599
         } else {
600
-            $invoice_id = wp_insert_post( $args );
600
+            $invoice_id = wp_insert_post($args);
601 601
             
602
-            $post_title = wpinv_format_invoice_number( $invoice_id );
602
+            $post_title = wpinv_format_invoice_number($invoice_id);
603 603
             global $wpdb;
604
-            $wpdb->update( $wpdb->posts, array( 'post_title' => $post_title, 'post_name' => sanitize_title( $post_title ) ), array( 'ID' => $invoice_id ) );
605
-            clean_post_cache( $invoice_id );
604
+            $wpdb->update($wpdb->posts, array('post_title' => $post_title, 'post_name' => sanitize_title($post_title)), array('ID' => $invoice_id));
605
+            clean_post_cache($invoice_id);
606 606
         }
607 607
 
608
-        if ( !empty( $invoice_id ) ) {             
608
+        if (!empty($invoice_id)) {             
609 609
             $this->ID  = $invoice_id;
610 610
             $this->_ID = $invoice_id;
611 611
             
612 612
             ///$this->pending['user_id'] = $this->user_id;
613
-            if ( isset( $this->pending['number'] ) ) {
613
+            if (isset($this->pending['number'])) {
614 614
                 $this->pending['number'] = $post_name;
615 615
             }
616 616
             
617
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
618
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
619
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
620
-                foreach( $this->fees as $fee ) {
621
-                    $this->increase_fees( $fee['amount'] );
617
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
618
+            if (!empty($this->payment_meta['fees'])) {
619
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
620
+                foreach ($this->fees as $fee) {
621
+                    $this->increase_fees($fee['amount']);
622 622
                 }
623 623
             }
624 624
 
625
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );            
625
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);            
626 626
             $this->new = true;
627 627
         }
628 628
 
629 629
         return $this->ID;
630 630
     }
631 631
 
632
-    public function save( $setup = false ) {
632
+    public function save($setup = false) {
633 633
         global $wpi_session;
634 634
         
635 635
         $saved = false;
636
-        if ( empty( $this->items ) ) {
636
+        if (empty($this->items)) {
637 637
             return $saved; // Don't save empty invoice.
638 638
         }
639 639
         
640
-        if ( empty( $this->key ) ) {
640
+        if (empty($this->key)) {
641 641
             $this->key = self::generate_key();
642 642
             $this->pending['key'] = $this->key;
643 643
         }
644 644
         
645
-        if ( empty( $this->ID ) ) {
645
+        if (empty($this->ID)) {
646 646
             $invoice_id = $this->insert_invoice();
647 647
 
648
-            if ( false === $invoice_id ) {
648
+            if (false === $invoice_id) {
649 649
                 $saved = false;
650 650
             } else {
651 651
                 $this->ID = $invoice_id;
@@ -653,27 +653,27 @@  discard block
 block discarded – undo
653 653
         }        
654 654
 
655 655
         // If we have something pending, let's save it
656
-        if ( !empty( $this->pending ) ) {
656
+        if (!empty($this->pending)) {
657 657
             $total_increase = 0;
658 658
             $total_decrease = 0;
659 659
 
660
-            foreach ( $this->pending as $key => $value ) {
661
-                switch( $key ) {
660
+            foreach ($this->pending as $key => $value) {
661
+                switch ($key) {
662 662
                     case 'items':
663 663
                         // Update totals for pending items
664
-                        foreach ( $this->pending[ $key ] as $item ) {
665
-                            switch( $item['action'] ) {
664
+                        foreach ($this->pending[$key] as $item) {
665
+                            switch ($item['action']) {
666 666
                                 case 'add':
667 667
                                     $price = $item['price'];
668 668
                                     $taxes = $item['tax'];
669 669
 
670
-                                    if ( 'publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status ) {
670
+                                    if ('publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status) {
671 671
                                         $total_increase += $price;
672 672
                                     }
673 673
                                     break;
674 674
 
675 675
                                 case 'remove':
676
-                                    if ( 'publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status ) {
676
+                                    if ('publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status) {
677 677
                                         $total_decrease += $item['price'];
678 678
                                     }
679 679
                                     break;
@@ -681,16 +681,16 @@  discard block
 block discarded – undo
681 681
                         }
682 682
                         break;
683 683
                     case 'fees':
684
-                        if ( 'publish' !== $this->status && 'complete' !== $this->status && 'revoked' !== $this->status ) {
684
+                        if ('publish' !== $this->status && 'complete' !== $this->status && 'revoked' !== $this->status) {
685 685
                             break;
686 686
                         }
687 687
 
688
-                        if ( empty( $this->pending[ $key ] ) ) {
688
+                        if (empty($this->pending[$key])) {
689 689
                             break;
690 690
                         }
691 691
 
692
-                        foreach ( $this->pending[ $key ] as $fee ) {
693
-                            switch( $fee['action'] ) {
692
+                        foreach ($this->pending[$key] as $fee) {
693
+                            switch ($fee['action']) {
694 694
                                 case 'add':
695 695
                                     $total_increase += $fee['amount'];
696 696
                                     break;
@@ -702,86 +702,86 @@  discard block
 block discarded – undo
702 702
                         }
703 703
                         break;
704 704
                     case 'status':
705
-                        $this->update_status( $this->status );
705
+                        $this->update_status($this->status);
706 706
                         break;
707 707
                     case 'gateway':
708
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
708
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
709 709
                         break;
710 710
                     case 'mode':
711
-                        $this->update_meta( '_wpinv_mode', $this->mode );
711
+                        $this->update_meta('_wpinv_mode', $this->mode);
712 712
                         break;
713 713
                     case 'transaction_id':
714
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
714
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
715 715
                         break;
716 716
                     case 'ip':
717
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
717
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
718 718
                         break;
719 719
                     ///case 'user_id':
720 720
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
721 721
                         ///$this->user_info['user_id'] = $this->user_id;
722 722
                         ///break;
723 723
                     case 'first_name':
724
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
724
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
725 725
                         $this->user_info['first_name'] = $this->first_name;
726 726
                         break;
727 727
                     case 'last_name':
728
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
728
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
729 729
                         $this->user_info['last_name'] = $this->last_name;
730 730
                         break;
731 731
                     case 'phone':
732
-                        $this->update_meta( '_wpinv_phone', $this->phone );
732
+                        $this->update_meta('_wpinv_phone', $this->phone);
733 733
                         $this->user_info['phone'] = $this->phone;
734 734
                         break;
735 735
                     case 'address':
736
-                        $this->update_meta( '_wpinv_address', $this->address );
736
+                        $this->update_meta('_wpinv_address', $this->address);
737 737
                         $this->user_info['address'] = $this->address;
738 738
                         break;
739 739
                     case 'city':
740
-                        $this->update_meta( '_wpinv_city', $this->city );
740
+                        $this->update_meta('_wpinv_city', $this->city);
741 741
                         $this->user_info['city'] = $this->city;
742 742
                         break;
743 743
                     case 'country':
744
-                        $this->update_meta( '_wpinv_country', $this->country );
744
+                        $this->update_meta('_wpinv_country', $this->country);
745 745
                         $this->user_info['country'] = $this->country;
746 746
                         break;
747 747
                     case 'state':
748
-                        $this->update_meta( '_wpinv_state', $this->state );
748
+                        $this->update_meta('_wpinv_state', $this->state);
749 749
                         $this->user_info['state'] = $this->state;
750 750
                         break;
751 751
                     case 'zip':
752
-                        $this->update_meta( '_wpinv_zip', $this->zip );
752
+                        $this->update_meta('_wpinv_zip', $this->zip);
753 753
                         $this->user_info['zip'] = $this->zip;
754 754
                         break;
755 755
                     case 'company':
756
-                        $this->update_meta( '_wpinv_company', $this->company );
756
+                        $this->update_meta('_wpinv_company', $this->company);
757 757
                         $this->user_info['company'] = $this->company;
758 758
                         break;
759 759
                     case 'vat_number':
760
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
760
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
761 761
                         $this->user_info['vat_number'] = $this->vat_number;
762 762
                         
763
-                        $vat_info = $wpi_session->get( 'user_vat_data' );
764
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
765
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
766
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
763
+                        $vat_info = $wpi_session->get('user_vat_data');
764
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
765
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
766
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool)$adddress_confirmed);
767 767
                             $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
768 768
                         }
769 769
     
770 770
                         break;
771 771
                     case 'vat_rate':
772
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
772
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
773 773
                         $this->user_info['vat_rate'] = $this->vat_rate;
774 774
                         break;
775 775
                     case 'adddress_confirmed':
776
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
776
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
777 777
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
778 778
                         break;
779 779
                     
780 780
                     case 'key':
781
-                        $this->update_meta( '_wpinv_key', $this->key );
781
+                        $this->update_meta('_wpinv_key', $this->key);
782 782
                         break;
783 783
                     case 'number':
784
-                        $this->update_meta( '_wpinv_number', $this->number );
784
+                        $this->update_meta('_wpinv_number', $this->number);
785 785
                         break;
786 786
                     case 'date':
787 787
                         $args = array(
@@ -790,34 +790,34 @@  discard block
 block discarded – undo
790 790
                             'edit_date' => true,
791 791
                         );
792 792
 
793
-                        wp_update_post( $args );
793
+                        wp_update_post($args);
794 794
                         break;
795 795
                     case 'due_date':
796
-                        if ( empty( $this->due_date ) ) {
796
+                        if (empty($this->due_date)) {
797 797
                             $this->due_date = 'none';
798 798
                         }
799 799
                         
800
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
800
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
801 801
                         break;
802 802
                     case 'completed_date':
803
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
803
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
804 804
                         break;
805 805
                     case 'discounts':
806
-                        if ( ! is_array( $this->discounts ) ) {
807
-                            $this->discounts = explode( ',', $this->discounts );
806
+                        if (!is_array($this->discounts)) {
807
+                            $this->discounts = explode(',', $this->discounts);
808 808
                         }
809 809
 
810
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
810
+                        $this->user_info['discount'] = implode(',', $this->discounts);
811 811
                         break;
812 812
                         
813 813
                     //case 'tax':
814 814
                         //$this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) );
815 815
                         //break;
816 816
                     case 'discount':
817
-                        $this->update_meta( '_wpinv_discount', wpinv_format_amount( $this->discount, NULL, true ) );
817
+                        $this->update_meta('_wpinv_discount', wpinv_format_amount($this->discount, NULL, true));
818 818
                         break;
819 819
                     case 'discount_code':
820
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
820
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
821 821
                         break;
822 822
                     //case 'fees':
823 823
                         //$this->update_meta( '_wpinv_fees', $this->fees );
@@ -827,19 +827,19 @@  discard block
 block discarded – undo
827 827
                             'ID'          => $this->ID,
828 828
                             'post_parent' => $this->parent_invoice,
829 829
                         );
830
-                        wp_update_post( $args );
830
+                        wp_update_post($args);
831 831
                         break;
832 832
                     default:
833
-                        do_action( 'wpinv_save', $this, $key );
833
+                        do_action('wpinv_save', $this, $key);
834 834
                         break;
835 835
                 }
836 836
             }       
837 837
 
838
-            $this->update_meta( '_wpinv_subtotal', wpinv_format_amount( $this->subtotal, NULL, true ) );
839
-            $this->update_meta( '_wpinv_total', wpinv_format_amount( $this->total, NULL, true ) );
840
-            $this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) );
838
+            $this->update_meta('_wpinv_subtotal', wpinv_format_amount($this->subtotal, NULL, true));
839
+            $this->update_meta('_wpinv_total', wpinv_format_amount($this->total, NULL, true));
840
+            $this->update_meta('_wpinv_tax', wpinv_format_amount($this->tax, NULL, true));
841 841
             
842
-            $this->items    = array_values( $this->items );
842
+            $this->items = array_values($this->items);
843 843
             
844 844
             $new_meta = array(
845 845
                 'items'         => $this->items,
@@ -849,13 +849,13 @@  discard block
 block discarded – undo
849 849
                 'user_info'     => $this->user_info,
850 850
             );
851 851
             
852
-            $meta        = $this->get_meta( '_wpinv_payment_meta', false );
853
-            $merged_meta = array_merge( $meta, $new_meta );
852
+            $meta        = $this->get_meta('_wpinv_payment_meta', false);
853
+            $merged_meta = array_merge($meta, $new_meta);
854 854
 
855 855
             // Only save the payment meta if it's changed
856
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
857
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
858
-                if ( false !== $updated ) {
856
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
857
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
858
+                if (false !== $updated) {
859 859
                     $saved = true;
860 860
                 }
861 861
             }
@@ -863,15 +863,15 @@  discard block
 block discarded – undo
863 863
             $this->pending = array();
864 864
             $saved         = true;
865 865
         } else {
866
-            $this->update_meta( '_wpinv_subtotal', wpinv_format_amount( $this->subtotal, NULL, true ) );
867
-            $this->update_meta( '_wpinv_total', wpinv_format_amount( $this->total, NULL, true ) );
868
-            $this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) );
866
+            $this->update_meta('_wpinv_subtotal', wpinv_format_amount($this->subtotal, NULL, true));
867
+            $this->update_meta('_wpinv_total', wpinv_format_amount($this->total, NULL, true));
868
+            $this->update_meta('_wpinv_tax', wpinv_format_amount($this->tax, NULL, true));
869 869
         }
870 870
         
871
-        do_action( 'wpinv_invoice_save', $this, $saved );
871
+        do_action('wpinv_invoice_save', $this, $saved);
872 872
 
873
-        if ( true === $saved || $setup ) {
874
-            $this->setup_invoice( $this->ID );
873
+        if (true === $saved || $setup) {
874
+            $this->setup_invoice($this->ID);
875 875
         }
876 876
         
877 877
         $this->refresh_item_ids();
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
         return $saved;
880 880
     }
881 881
     
882
-    public function add_fee( $args, $global = true ) {
882
+    public function add_fee($args, $global = true) {
883 883
         $default_args = array(
884 884
             'label'       => '',
885 885
             'amount'      => 0,
@@ -889,75 +889,75 @@  discard block
 block discarded – undo
889 889
             'item_id'     => 0,
890 890
         );
891 891
 
892
-        $fee = wp_parse_args( $args, $default_args );
892
+        $fee = wp_parse_args($args, $default_args);
893 893
         
894
-        if ( !empty( $fee['label'] ) ) {
894
+        if (!empty($fee['label'])) {
895 895
             return false;
896 896
         }
897 897
         
898
-        $fee['id']  = sanitize_title( $fee['label'] );
898
+        $fee['id'] = sanitize_title($fee['label']);
899 899
         
900
-        $this->fees[]               = $fee;
900
+        $this->fees[] = $fee;
901 901
         
902 902
         $added_fee               = $fee;
903 903
         $added_fee['action']     = 'add';
904 904
         $this->pending['fees'][] = $added_fee;
905
-        reset( $this->fees );
905
+        reset($this->fees);
906 906
 
907
-        $this->increase_fees( $fee['amount'] );
907
+        $this->increase_fees($fee['amount']);
908 908
         return true;
909 909
     }
910 910
 
911
-    public function remove_fee( $key ) {
911
+    public function remove_fee($key) {
912 912
         $removed = false;
913 913
 
914
-        if ( is_numeric( $key ) ) {
915
-            $removed = $this->remove_fee_by( 'index', $key );
914
+        if (is_numeric($key)) {
915
+            $removed = $this->remove_fee_by('index', $key);
916 916
         }
917 917
 
918 918
         return $removed;
919 919
     }
920 920
 
921
-    public function remove_fee_by( $key, $value, $global = false ) {
922
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
921
+    public function remove_fee_by($key, $value, $global = false) {
922
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
923 923
             'index', 'label', 'amount', 'type',
924
-        ) );
924
+        ));
925 925
 
926
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
926
+        if (!in_array($key, $allowed_fee_keys)) {
927 927
             return false;
928 928
         }
929 929
 
930 930
         $removed = false;
931
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
932
-            $removed_fee             = $this->fees[ $value ];
931
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
932
+            $removed_fee             = $this->fees[$value];
933 933
             $removed_fee['action']   = 'remove';
934 934
             $this->pending['fees'][] = $removed_fee;
935 935
 
936
-            $this->decrease_fees( $removed_fee['amount'] );
936
+            $this->decrease_fees($removed_fee['amount']);
937 937
 
938
-            unset( $this->fees[ $value ] );
938
+            unset($this->fees[$value]);
939 939
             $removed = true;
940
-        } else if ( 'index' !== $key ) {
941
-            foreach ( $this->fees as $index => $fee ) {
942
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
940
+        } else if ('index' !== $key) {
941
+            foreach ($this->fees as $index => $fee) {
942
+                if (isset($fee[$key]) && $fee[$key] == $value) {
943 943
                     $removed_fee             = $fee;
944 944
                     $removed_fee['action']   = 'remove';
945 945
                     $this->pending['fees'][] = $removed_fee;
946 946
 
947
-                    $this->decrease_fees( $removed_fee['amount'] );
947
+                    $this->decrease_fees($removed_fee['amount']);
948 948
 
949
-                    unset( $this->fees[ $index ] );
949
+                    unset($this->fees[$index]);
950 950
                     $removed = true;
951 951
 
952
-                    if ( false === $global ) {
952
+                    if (false === $global) {
953 953
                         break;
954 954
                     }
955 955
                 }
956 956
             }
957 957
         }
958 958
 
959
-        if ( true === $removed ) {
960
-            $this->fees = array_values( $this->fees );
959
+        if (true === $removed) {
960
+            $this->fees = array_values($this->fees);
961 961
         }
962 962
 
963 963
         return $removed;
@@ -965,35 +965,35 @@  discard block
 block discarded – undo
965 965
 
966 966
     
967 967
 
968
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
968
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
969 969
         // Bail if no note specified
970
-        if( !$note ) {
970
+        if (!$note) {
971 971
             return false;
972 972
         }
973 973
 
974
-        if ( empty( $this->ID ) )
974
+        if (empty($this->ID))
975 975
             return false;
976 976
         
977
-        if ( ( ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || $added_by_user ) && !$system ) {
978
-            $user                 = get_user_by( 'id', get_current_user_id() );
977
+        if (((is_user_logged_in() && current_user_can('manage_options')) || $added_by_user) && !$system) {
978
+            $user                 = get_user_by('id', get_current_user_id());
979 979
             $comment_author       = $user->display_name;
980 980
             $comment_author_email = $user->user_email;
981 981
         } else {
982
-            $comment_author       = __( 'System', 'invoicing' );
983
-            $comment_author_email = strtolower( __( 'System', 'invoicing' ) ) . '@';
984
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
985
-            $comment_author_email = sanitize_email( $comment_author_email );
982
+            $comment_author       = __('System', 'invoicing');
983
+            $comment_author_email = strtolower(__('System', 'invoicing')) . '@';
984
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
985
+            $comment_author_email = sanitize_email($comment_author_email);
986 986
         }
987 987
 
988
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
988
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
989 989
 
990
-        $note_id = wp_insert_comment( wp_filter_comment( array(
990
+        $note_id = wp_insert_comment(wp_filter_comment(array(
991 991
             'comment_post_ID'      => $this->ID,
992 992
             'comment_content'      => $note,
993 993
             'comment_agent'        => 'GeoDirectory',
994 994
             'user_id'              => is_admin() ? get_current_user_id() : 0,
995
-            'comment_date'         => current_time( 'mysql' ),
996
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
995
+            'comment_date'         => current_time('mysql'),
996
+            'comment_date_gmt'     => current_time('mysql', 1),
997 997
             'comment_approved'     => 1,
998 998
             'comment_parent'       => 0,
999 999
             'comment_author'       => $comment_author,
@@ -1001,53 +1001,53 @@  discard block
 block discarded – undo
1001 1001
             'comment_author_url'   => '',
1002 1002
             'comment_author_email' => $comment_author_email,
1003 1003
             'comment_type'         => 'wpinv_note'
1004
-        ) ) );
1004
+        )));
1005 1005
 
1006
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1006
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1007 1007
         
1008
-        if ( $customer_type ) {
1009
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1008
+        if ($customer_type) {
1009
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1010 1010
 
1011
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1011
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1012 1012
         }
1013 1013
 
1014 1014
         return $note_id;
1015 1015
     }
1016 1016
 
1017
-    private function increase_subtotal( $amount = 0.00 ) {
1018
-        $amount          = (float) $amount;
1017
+    private function increase_subtotal($amount = 0.00) {
1018
+        $amount          = (float)$amount;
1019 1019
         $this->subtotal += $amount;
1020
-        $this->subtotal  = wpinv_format_amount( $this->subtotal, NULL, true );
1020
+        $this->subtotal  = wpinv_format_amount($this->subtotal, NULL, true);
1021 1021
 
1022 1022
         $this->recalculate_total();
1023 1023
     }
1024 1024
 
1025
-    private function decrease_subtotal( $amount = 0.00 ) {
1026
-        $amount          = (float) $amount;
1025
+    private function decrease_subtotal($amount = 0.00) {
1026
+        $amount          = (float)$amount;
1027 1027
         $this->subtotal -= $amount;
1028
-        $this->subtotal  = wpinv_format_amount( $this->subtotal, NULL, true );
1028
+        $this->subtotal  = wpinv_format_amount($this->subtotal, NULL, true);
1029 1029
 
1030
-        if ( $this->subtotal < 0 ) {
1030
+        if ($this->subtotal < 0) {
1031 1031
             $this->subtotal = 0;
1032 1032
         }
1033 1033
 
1034 1034
         $this->recalculate_total();
1035 1035
     }
1036 1036
 
1037
-    private function increase_fees( $amount = 0.00 ) {
1037
+    private function increase_fees($amount = 0.00) {
1038 1038
         $amount            = (float)$amount;
1039 1039
         $this->fees_total += $amount;
1040
-        $this->fees_total  = wpinv_format_amount( $this->fees_total, NULL, true );
1040
+        $this->fees_total  = wpinv_format_amount($this->fees_total, NULL, true);
1041 1041
 
1042 1042
         $this->recalculate_total();
1043 1043
     }
1044 1044
 
1045
-    private function decrease_fees( $amount = 0.00 ) {
1046
-        $amount            = (float) $amount;
1045
+    private function decrease_fees($amount = 0.00) {
1046
+        $amount            = (float)$amount;
1047 1047
         $this->fees_total -= $amount;
1048
-        $this->fees_total  = wpinv_format_amount( $this->fees_total, NULL, true );
1048
+        $this->fees_total  = wpinv_format_amount($this->fees_total, NULL, true);
1049 1049
 
1050
-        if ( $this->fees_total < 0 ) {
1050
+        if ($this->fees_total < 0) {
1051 1051
             $this->fees_total = 0;
1052 1052
         }
1053 1053
 
@@ -1058,54 +1058,54 @@  discard block
 block discarded – undo
1058 1058
         global $wpi_nosave;
1059 1059
         
1060 1060
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1061
-        $this->total = wpinv_format_amount( $this->total, NULL, true );
1061
+        $this->total = wpinv_format_amount($this->total, NULL, true);
1062 1062
         
1063
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1063
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1064 1064
     }
1065 1065
     
1066
-    public function increase_tax( $amount = 0.00 ) {
1067
-        $amount       = (float) $amount;
1066
+    public function increase_tax($amount = 0.00) {
1067
+        $amount       = (float)$amount;
1068 1068
         $this->tax   += $amount;
1069 1069
 
1070 1070
         $this->recalculate_total();
1071 1071
     }
1072 1072
 
1073
-    public function decrease_tax( $amount = 0.00 ) {
1074
-        $amount     = (float) $amount;
1073
+    public function decrease_tax($amount = 0.00) {
1074
+        $amount     = (float)$amount;
1075 1075
         $this->tax -= $amount;
1076 1076
 
1077
-        if ( $this->tax < 0 ) {
1077
+        if ($this->tax < 0) {
1078 1078
             $this->tax = 0;
1079 1079
         }
1080 1080
 
1081 1081
         $this->recalculate_total();
1082 1082
     }
1083 1083
 
1084
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1085
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1084
+    public function update_status($new_status = false, $note = '', $manual = false) {
1085
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1086 1086
         
1087
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses() ) ) ) {
1087
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses()))) {
1088 1088
             return false; // Don't permit status changes that aren't changes
1089 1089
         }
1090 1090
 
1091
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1091
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1092 1092
         $updated = false;
1093 1093
 
1094
-        if ( $do_change ) {
1095
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1094
+        if ($do_change) {
1095
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1096 1096
 
1097 1097
             $update_post_data                   = array();
1098 1098
             $update_post_data['ID']             = $this->ID;
1099 1099
             $update_post_data['post_status']    = $new_status;
1100
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1101
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1100
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1101
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1102 1102
             
1103
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1103
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1104 1104
 
1105
-            $updated = wp_update_post( $update_post_data );     
1105
+            $updated = wp_update_post($update_post_data);     
1106 1106
            
1107 1107
             // Process any specific status functions
1108
-            switch( $new_status ) {
1108
+            switch ($new_status) {
1109 1109
                 case 'refunded':
1110 1110
                     $this->process_refund();
1111 1111
                     break;
@@ -1118,9 +1118,9 @@  discard block
 block discarded – undo
1118 1118
             }
1119 1119
             
1120 1120
             // Status was changed.
1121
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1122
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1123
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1121
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1122
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1123
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1124 1124
         }
1125 1125
 
1126 1126
         return $updated;
@@ -1134,72 +1134,72 @@  discard block
 block discarded – undo
1134 1134
         $this->save();
1135 1135
     }
1136 1136
 
1137
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1138
-        if ( empty( $meta_key ) ) {
1137
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1138
+        if (empty($meta_key)) {
1139 1139
             return false;
1140 1140
         }
1141 1141
 
1142
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1143
-            $current_meta = $this->get_meta( '_wpinv_payment_meta', false );
1144
-            $current_meta[ $meta_key ] = $meta_value;
1142
+        if ($meta_key == 'key' || $meta_key == 'date') {
1143
+            $current_meta = $this->get_meta('_wpinv_payment_meta', false);
1144
+            $current_meta[$meta_key] = $meta_value;
1145 1145
 
1146 1146
             $meta_key     = '_wpinv_payment_meta';
1147 1147
             $meta_value   = $current_meta;
1148 1148
         }
1149 1149
 
1150
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1150
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1151 1151
         
1152
-        if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
1152
+        if ($meta_key == '_wpinv_completed_date' && !empty($meta_value)) {
1153 1153
             $args = array(
1154 1154
                 'ID'                => $this->ID,
1155 1155
                 'post_date'         => $meta_value,
1156 1156
                 'edit_date'         => true,
1157
-                'post_date_gmt'     => get_gmt_from_date( $meta_value ),
1157
+                'post_date_gmt'     => get_gmt_from_date($meta_value),
1158 1158
                 'post_modified'     => $meta_value,
1159
-                'post_modified_gmt' => get_gmt_from_date( $meta_value )
1159
+                'post_modified_gmt' => get_gmt_from_date($meta_value)
1160 1160
             );
1161
-            wp_update_post( $args );
1161
+            wp_update_post($args);
1162 1162
         }
1163 1163
         
1164
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1164
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1165 1165
     }
1166 1166
 
1167 1167
     private function process_refund() {
1168 1168
         $process_refund = true;
1169 1169
 
1170 1170
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1171
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'refunded' != $this->status ) {
1171
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'refunded' != $this->status) {
1172 1172
             $process_refund = false;
1173 1173
         }
1174 1174
 
1175 1175
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1176
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1176
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1177 1177
 
1178
-        if ( false === $process_refund ) {
1178
+        if (false === $process_refund) {
1179 1179
             return;
1180 1180
         }
1181 1181
 
1182
-        do_action( 'wpinv_pre_refund_invoice', $this );
1182
+        do_action('wpinv_pre_refund_invoice', $this);
1183 1183
         
1184
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1185
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1186
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1184
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1185
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1186
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1187 1187
         
1188
-        do_action( 'wpinv_post_refund_invoice', $this );
1188
+        do_action('wpinv_post_refund_invoice', $this);
1189 1189
     }
1190 1190
 
1191 1191
     private function process_failure() {
1192 1192
         $discounts = $this->discounts;
1193
-        if ( empty( $discounts ) ) {
1193
+        if (empty($discounts)) {
1194 1194
             return;
1195 1195
         }
1196 1196
 
1197
-        if ( ! is_array( $discounts ) ) {
1198
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1197
+        if (!is_array($discounts)) {
1198
+            $discounts = array_map('trim', explode(',', $discounts));
1199 1199
         }
1200 1200
 
1201
-        foreach ( $discounts as $discount ) {
1202
-            wpinv_decrease_discount_usage( $discount );
1201
+        foreach ($discounts as $discount) {
1202
+            wpinv_decrease_discount_usage($discount);
1203 1203
         }
1204 1204
     }
1205 1205
     
@@ -1207,101 +1207,101 @@  discard block
 block discarded – undo
1207 1207
         $process_pending = true;
1208 1208
 
1209 1209
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1210
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'pending' != $this->status ) {
1210
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'pending' != $this->status) {
1211 1211
             $process_pending = false;
1212 1212
         }
1213 1213
 
1214 1214
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1215
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1215
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1216 1216
 
1217
-        if ( false === $process_pending ) {
1217
+        if (false === $process_pending) {
1218 1218
             return;
1219 1219
         }
1220 1220
 
1221
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1222
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1223
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1221
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1222
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1223
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1224 1224
 
1225 1225
         $this->completed_date = '';
1226
-        $this->update_meta( '_wpinv_completed_date', '' );
1226
+        $this->update_meta('_wpinv_completed_date', '');
1227 1227
     }
1228 1228
     
1229 1229
     // get data
1230
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = false ) {
1231
-        if ( empty( $meta_key ) || $meta_key == 'payment_meta' ) {
1230
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = false) {
1231
+        if (empty($meta_key) || $meta_key == 'payment_meta') {
1232 1232
             $meta_key = '_wpinv_payment_meta';
1233 1233
         }
1234 1234
         
1235
-        if ( $meta_key == '_wpinv_payment_meta' ) {
1235
+        if ($meta_key == '_wpinv_payment_meta') {
1236 1236
             $single = false;
1237 1237
         }
1238 1238
         
1239
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1239
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1240 1240
 
1241
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1242
-            if ( !is_array( $meta ) ) {
1241
+        if ($meta_key === '_wpinv_payment_meta') {
1242
+            if (!is_array($meta)) {
1243 1243
                 $meta = array();
1244 1244
             }
1245 1245
             
1246
-            if ( empty( $meta['key'] ) ) {
1246
+            if (empty($meta['key'])) {
1247 1247
                 $meta['key'] = $this->setup_invoice_key();
1248 1248
             }
1249 1249
 
1250
-            if ( empty( $meta['date'] ) ) {
1251
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1250
+            if (empty($meta['date'])) {
1251
+                $meta['date'] = get_post_field('post_date', $this->ID);
1252 1252
             }
1253 1253
         }
1254 1254
         
1255
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1255
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1256 1256
 
1257
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1257
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1258 1258
     }
1259 1259
     
1260 1260
     public function get_description() {
1261
-        $post = get_post( $this->ID );
1261
+        $post = get_post($this->ID);
1262 1262
         
1263
-        $description = !empty( $post ) ? $post->post_content : '';
1264
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1263
+        $description = !empty($post) ? $post->post_content : '';
1264
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1265 1265
     }
1266 1266
     
1267
-    public function get_status( $nicename = false ) {
1268
-        if ( !$nicename ) {
1267
+    public function get_status($nicename = false) {
1268
+        if (!$nicename) {
1269 1269
             $status = $this->status;
1270 1270
         } else {
1271 1271
             $status = $this->status_nicename;
1272 1272
         }
1273 1273
         
1274
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1274
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1275 1275
     }
1276 1276
     
1277 1277
     public function get_cart_details() {
1278
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1278
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1279 1279
     }
1280 1280
     
1281
-    public function get_subtotal( $currency = false ) {
1282
-        $subtotal = wpinv_format_amount( $this->subtotal, NULL, !$currency );
1281
+    public function get_subtotal($currency = false) {
1282
+        $subtotal = wpinv_format_amount($this->subtotal, NULL, !$currency);
1283 1283
         
1284
-        if ( $currency ) {
1285
-            $subtotal = wpinv_price( $subtotal, $this->get_currency() );
1284
+        if ($currency) {
1285
+            $subtotal = wpinv_price($subtotal, $this->get_currency());
1286 1286
         }
1287 1287
         
1288
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1288
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1289 1289
     }
1290 1290
     
1291
-    public function get_total( $currency = false ) {        
1292
-        if ( $this->is_free_trial() ) {
1293
-            $total = wpinv_format_amount( 0, NULL, !$currency );
1291
+    public function get_total($currency = false) {        
1292
+        if ($this->is_free_trial()) {
1293
+            $total = wpinv_format_amount(0, NULL, !$currency);
1294 1294
         } else {
1295
-            $total = wpinv_format_amount( $this->total, NULL, !$currency );
1295
+            $total = wpinv_format_amount($this->total, NULL, !$currency);
1296 1296
         }
1297
-        if ( $currency ) {
1298
-            $total = wpinv_price( $total, $this->get_currency() );
1297
+        if ($currency) {
1298
+            $total = wpinv_price($total, $this->get_currency());
1299 1299
         }
1300 1300
         
1301
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1301
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1302 1302
     }
1303 1303
     
1304
-    public function get_recurring_details( $field = '', $currency = false ) {        
1304
+    public function get_recurring_details($field = '', $currency = false) {        
1305 1305
         $data                 = array();
1306 1306
         $data['cart_details'] = $this->cart_details;
1307 1307
         $data['subtotal']     = $this->get_subtotal();
@@ -1309,45 +1309,45 @@  discard block
 block discarded – undo
1309 1309
         $data['tax']          = $this->get_tax();
1310 1310
         $data['total']        = $this->get_total();
1311 1311
     
1312
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1312
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1313 1313
             $is_free_trial = $this->is_free_trial();
1314
-            $discounts = $this->get_discounts( true );
1314
+            $discounts = $this->get_discounts(true);
1315 1315
             
1316
-            if ( $is_free_trial || !empty( $discounts ) ) {
1316
+            if ($is_free_trial || !empty($discounts)) {
1317 1317
                 $first_use_only = false;
1318 1318
                 
1319
-                if ( !empty( $discounts ) ) {
1320
-                    foreach ( $discounts as $key => $code ) {
1321
-                        if ( wpinv_discount_is_recurring( $code, true ) ) {
1319
+                if (!empty($discounts)) {
1320
+                    foreach ($discounts as $key => $code) {
1321
+                        if (wpinv_discount_is_recurring($code, true)) {
1322 1322
                             $first_use_only = true;
1323 1323
                             break;
1324 1324
                         }
1325 1325
                     }
1326 1326
                 }
1327 1327
                     
1328
-                if ( !$first_use_only ) {
1329
-                    $data['subtotal'] = wpinv_format_amount( $this->subtotal, NULL, true );
1330
-                    $data['discount'] = wpinv_format_amount( $this->discount, NULL, true );
1331
-                    $data['tax']      = wpinv_format_amount( $this->tax, NULL, true );
1332
-                    $data['total']    = wpinv_format_amount( $this->total, NULL, true );
1328
+                if (!$first_use_only) {
1329
+                    $data['subtotal'] = wpinv_format_amount($this->subtotal, NULL, true);
1330
+                    $data['discount'] = wpinv_format_amount($this->discount, NULL, true);
1331
+                    $data['tax']      = wpinv_format_amount($this->tax, NULL, true);
1332
+                    $data['total']    = wpinv_format_amount($this->total, NULL, true);
1333 1333
                 } else {
1334 1334
                     $cart_subtotal   = 0;
1335 1335
                     $cart_discount   = 0;
1336 1336
                     $cart_tax        = 0;
1337 1337
 
1338
-                    foreach ( $this->cart_details as $key => $item ) {
1339
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1340
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1338
+                    foreach ($this->cart_details as $key => $item) {
1339
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1340
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1341 1341
                         $item_discount  = 0;
1342
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1342
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float)$item['vat_rate']) : 0;
1343 1343
                         
1344
-                        if ( wpinv_prices_include_tax() ) {
1345
-                            $item_subtotal -= wpinv_format_amount( $item_tax, NULL, true );
1344
+                        if (wpinv_prices_include_tax()) {
1345
+                            $item_subtotal -= wpinv_format_amount($item_tax, NULL, true);
1346 1346
                         }
1347 1347
                         
1348 1348
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1349 1349
                         // Do not allow totals to go negative
1350
-                        if ( $item_total < 0 ) {
1350
+                        if ($item_total < 0) {
1351 1351
                             $item_total = 0;
1352 1352
                         }
1353 1353
                         
@@ -1355,107 +1355,107 @@  discard block
 block discarded – undo
1355 1355
                         $cart_discount  += (float)($item_discount);
1356 1356
                         $cart_tax       += (float)($item_tax);
1357 1357
                         
1358
-                        $data['cart_details'][$key]['discount']   = wpinv_format_amount( $item_discount, NULL, true );
1359
-                        $data['cart_details'][$key]['tax']        = wpinv_format_amount( $item_tax, NULL, true );
1360
-                        $data['cart_details'][$key]['price']      = wpinv_format_amount( $item_total, NULL, true );
1358
+                        $data['cart_details'][$key]['discount']   = wpinv_format_amount($item_discount, NULL, true);
1359
+                        $data['cart_details'][$key]['tax']        = wpinv_format_amount($item_tax, NULL, true);
1360
+                        $data['cart_details'][$key]['price']      = wpinv_format_amount($item_total, NULL, true);
1361 1361
                     }
1362 1362
                     
1363
-                    $data['subtotal'] = wpinv_format_amount( $cart_subtotal, NULL, true );
1364
-                    $data['discount'] = wpinv_format_amount( $cart_discount, NULL, true );
1365
-                    $data['tax']      = wpinv_format_amount( $cart_tax, NULL, true );
1366
-                    $data['total']    = wpinv_format_amount( ( $data['subtotal'] + $data['tax'] ), NULL, true );
1363
+                    $data['subtotal'] = wpinv_format_amount($cart_subtotal, NULL, true);
1364
+                    $data['discount'] = wpinv_format_amount($cart_discount, NULL, true);
1365
+                    $data['tax']      = wpinv_format_amount($cart_tax, NULL, true);
1366
+                    $data['total']    = wpinv_format_amount(($data['subtotal'] + $data['tax']), NULL, true);
1367 1367
                 }
1368 1368
             }
1369 1369
         }
1370 1370
         
1371
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1371
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1372 1372
 
1373
-        if ( isset( $data[$field] ) ) {
1374
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1373
+        if (isset($data[$field])) {
1374
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1375 1375
         }
1376 1376
         
1377 1377
         return $data;
1378 1378
     }
1379 1379
     
1380
-    public function get_final_tax( $currency = false ) {        
1381
-        $final_total = wpinv_format_amount( $this->tax, NULL, !$currency );
1382
-        if ( $currency ) {
1383
-            $final_total = wpinv_price( $final_total, $this->get_currency() );
1380
+    public function get_final_tax($currency = false) {        
1381
+        $final_total = wpinv_format_amount($this->tax, NULL, !$currency);
1382
+        if ($currency) {
1383
+            $final_total = wpinv_price($final_total, $this->get_currency());
1384 1384
         }
1385 1385
         
1386
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1386
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1387 1387
     }
1388 1388
     
1389
-    public function get_discounts( $array = false ) {
1389
+    public function get_discounts($array = false) {
1390 1390
         $discounts = $this->discounts;
1391
-        if ( $array && $discounts ) {
1392
-            $discounts = explode( ',', $discounts );
1391
+        if ($array && $discounts) {
1392
+            $discounts = explode(',', $discounts);
1393 1393
         }
1394
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1394
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1395 1395
     }
1396 1396
     
1397
-    public function get_discount( $currency = false, $dash = false ) {
1398
-        if ( !empty( $this->discounts ) ) {
1397
+    public function get_discount($currency = false, $dash = false) {
1398
+        if (!empty($this->discounts)) {
1399 1399
             global $ajax_cart_details;
1400 1400
             $ajax_cart_details = $this->get_cart_details();
1401 1401
 
1402
-            $this->discount = wpinv_get_cart_items_discount_amount( $this->items , $this->discounts );
1402
+            $this->discount = wpinv_get_cart_items_discount_amount($this->items, $this->discounts);
1403 1403
         }
1404
-        $discount   = wpinv_format_amount( $this->discount, NULL, !$currency );
1404
+        $discount   = wpinv_format_amount($this->discount, NULL, !$currency);
1405 1405
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1406 1406
         
1407
-        if ( $currency ) {
1408
-            $discount = wpinv_price( $discount, $this->get_currency() );
1407
+        if ($currency) {
1408
+            $discount = wpinv_price($discount, $this->get_currency());
1409 1409
         }
1410 1410
         
1411
-        $discount   = $dash . $discount;
1411
+        $discount = $dash . $discount;
1412 1412
         
1413
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1413
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1414 1414
     }
1415 1415
     
1416 1416
     public function get_discount_code() {
1417 1417
         return $this->discount_code;
1418 1418
     }
1419 1419
     
1420
-    public function get_tax( $currency = false ) {
1421
-        $tax = wpinv_format_amount( $this->tax, NULL, !$currency );
1420
+    public function get_tax($currency = false) {
1421
+        $tax = wpinv_format_amount($this->tax, NULL, !$currency);
1422 1422
         
1423
-        if ( $currency ) {
1424
-            $tax = wpinv_price( $tax, $this->get_currency() );
1423
+        if ($currency) {
1424
+            $tax = wpinv_price($tax, $this->get_currency());
1425 1425
         }
1426 1426
         
1427
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1427
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1428 1428
     }
1429 1429
     
1430
-    public function get_fees( $type = 'all' ) {
1431
-        $fees    = array();
1430
+    public function get_fees($type = 'all') {
1431
+        $fees = array();
1432 1432
 
1433
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1434
-            foreach ( $this->fees as $fee ) {
1435
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1433
+        if (!empty($this->fees) && is_array($this->fees)) {
1434
+            foreach ($this->fees as $fee) {
1435
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1436 1436
                     continue;
1437 1437
                 }
1438 1438
 
1439
-                $fee['label'] = stripslashes( $fee['label'] );
1440
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1441
-                $fees[]    = $fee;
1439
+                $fee['label'] = stripslashes($fee['label']);
1440
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1441
+                $fees[] = $fee;
1442 1442
             }
1443 1443
         }
1444 1444
 
1445
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1445
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1446 1446
     }
1447 1447
     
1448
-    public function get_fees_total( $type = 'all' ) {
1449
-        $fees_total = (float) 0.00;
1448
+    public function get_fees_total($type = 'all') {
1449
+        $fees_total = (float)0.00;
1450 1450
 
1451
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1452
-        if ( ! empty( $payment_fees ) ) {
1453
-            foreach ( $payment_fees as $fee ) {
1454
-                $fees_total += (float) $fee['amount'];
1451
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1452
+        if (!empty($payment_fees)) {
1453
+            foreach ($payment_fees as $fee) {
1454
+                $fees_total += (float)$fee['amount'];
1455 1455
             }
1456 1456
         }
1457 1457
 
1458
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1458
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1459 1459
         /*
1460 1460
         $fees = $this->get_fees( $type );
1461 1461
 
@@ -1475,116 +1475,116 @@  discard block
 block discarded – undo
1475 1475
     }
1476 1476
 
1477 1477
     public function get_user_id() {
1478
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1478
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1479 1479
     }
1480 1480
     
1481 1481
     public function get_first_name() {
1482
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1482
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1483 1483
     }
1484 1484
     
1485 1485
     public function get_last_name() {
1486
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1486
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1487 1487
     }
1488 1488
     
1489 1489
     public function get_user_full_name() {
1490
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1490
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1491 1491
     }
1492 1492
     
1493 1493
     public function get_user_info() {
1494
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1494
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1495 1495
     }
1496 1496
     
1497 1497
     public function get_email() {
1498
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1498
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1499 1499
     }
1500 1500
     
1501 1501
     public function get_address() {
1502
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1502
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1503 1503
     }
1504 1504
     
1505 1505
     public function get_phone() {
1506
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1506
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1507 1507
     }
1508 1508
     
1509 1509
     public function get_number() {
1510
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1510
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1511 1511
     }
1512 1512
     
1513 1513
     public function get_items() {
1514
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1514
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1515 1515
     }
1516 1516
     
1517 1517
     public function get_key() {
1518
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1518
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1519 1519
     }
1520 1520
     
1521 1521
     public function get_transaction_id() {
1522
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1522
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1523 1523
     }
1524 1524
     
1525 1525
     public function get_gateway() {
1526
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1526
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1527 1527
     }
1528 1528
     
1529 1529
     public function get_gateway_title() {
1530
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1530
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1531 1531
         
1532
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1532
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1533 1533
     }
1534 1534
     
1535 1535
     public function get_currency() {
1536
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1536
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1537 1537
     }
1538 1538
     
1539 1539
     public function get_created_date() {
1540
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1540
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1541 1541
     }
1542 1542
     
1543
-    public function get_due_date( $display = false ) {
1544
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1543
+    public function get_due_date($display = false) {
1544
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1545 1545
         
1546
-        if ( !$display || empty( $due_date ) ) {
1546
+        if (!$display || empty($due_date)) {
1547 1547
             return $due_date;
1548 1548
         }
1549 1549
         
1550
-        return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );
1550
+        return date_i18n(get_option('date_format'), strtotime($due_date));
1551 1551
     }
1552 1552
     
1553 1553
     public function get_completed_date() {
1554
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1554
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1555 1555
     }
1556 1556
     
1557
-    public function get_invoice_date( $formatted = true ) {
1557
+    public function get_invoice_date($formatted = true) {
1558 1558
         $date_completed = $this->completed_date;
1559 1559
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1560 1560
         
1561
-        if ( $invoice_date == '' ) {
1561
+        if ($invoice_date == '') {
1562 1562
             $date_created   = $this->date;
1563 1563
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1564 1564
         }
1565 1565
         
1566
-        if ( $formatted && $invoice_date ) {
1567
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
1566
+        if ($formatted && $invoice_date) {
1567
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
1568 1568
         }
1569 1569
 
1570
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1570
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1571 1571
     }
1572 1572
     
1573 1573
     public function get_ip() {
1574
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1574
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1575 1575
     }
1576 1576
         
1577
-    public function has_status( $status ) {
1578
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1577
+    public function has_status($status) {
1578
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1579 1579
     }
1580 1580
     
1581
-    public function add_item( $item_id = 0, $args = array() ) {
1581
+    public function add_item($item_id = 0, $args = array()) {
1582 1582
         global $wpi_current_id, $wpi_item_id;
1583 1583
         
1584
-        $item = new WPInv_Item( $item_id );
1584
+        $item = new WPInv_Item($item_id);
1585 1585
 
1586 1586
         // Bail if this post isn't a item
1587
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1587
+        if (!$item || $item->post_type !== 'wpi_item') {
1588 1588
             return false;
1589 1589
         }
1590 1590
         
@@ -1602,8 +1602,8 @@  discard block
 block discarded – undo
1602 1602
             'fees'      => array()
1603 1603
         );
1604 1604
 
1605
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1606
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1605
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1606
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1607 1607
 
1608 1608
         $wpi_current_id         = $this->ID;
1609 1609
         $wpi_item_id            = $item->ID;
@@ -1615,19 +1615,19 @@  discard block
 block discarded – undo
1615 1615
         $found_cart_key         = false;
1616 1616
         
1617 1617
         if ($has_quantities) {
1618
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1618
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1619 1619
             
1620
-            foreach ( $this->items as $key => $cart_item ) {
1621
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1620
+            foreach ($this->items as $key => $cart_item) {
1621
+                if ((int)$item_id !== (int)$cart_item['id']) {
1622 1622
                     continue;
1623 1623
                 }
1624 1624
 
1625
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1625
+                $this->items[$key]['quantity'] += $args['quantity'];
1626 1626
                 break;
1627 1627
             }
1628 1628
             
1629
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1630
-                if ( $item_id != $cart_item['id'] ) {
1629
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1630
+                if ($item_id != $cart_item['id']) {
1631 1631
                     continue;
1632 1632
                 }
1633 1633
 
@@ -1639,29 +1639,29 @@  discard block
 block discarded – undo
1639 1639
         if ($has_quantities && $found_cart_key !== false) {
1640 1640
             $cart_item          = $this->cart_details[$found_cart_key];
1641 1641
             $item_price         = $cart_item['item_price'];
1642
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1643
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1642
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1643
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1644 1644
             
1645 1645
             $new_quantity       = $quantity + $args['quantity'];
1646 1646
             $subtotal           = $item_price * $new_quantity;
1647 1647
             
1648 1648
             $args['quantity']   = $new_quantity;
1649
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1650
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1649
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1650
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1651 1651
             
1652 1652
             $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1653 1653
             $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1654 1654
             // The total increase equals the number removed * the item_price
1655
-            $total_increased    = wpinv_format_amount( $item_price, NULL, true );
1655
+            $total_increased    = wpinv_format_amount($item_price, NULL, true);
1656 1656
             
1657
-            if ( wpinv_prices_include_tax() ) {
1658
-                $subtotal -= wpinv_format_amount( $tax, NULL, true );
1657
+            if (wpinv_prices_include_tax()) {
1658
+                $subtotal -= wpinv_format_amount($tax, NULL, true);
1659 1659
             }
1660 1660
 
1661
-            $total              = $subtotal - $discount + $tax;
1661
+            $total = $subtotal - $discount + $tax;
1662 1662
 
1663 1663
             // Do not allow totals to go negative
1664
-            if( $total < 0 ) {
1664
+            if ($total < 0) {
1665 1665
                 $total = 0;
1666 1666
             }
1667 1667
             
@@ -1677,20 +1677,20 @@  discard block
 block discarded – undo
1677 1677
             $this->cart_details[$found_cart_key] = $cart_item;
1678 1678
         } else {
1679 1679
             // Allow overriding the price
1680
-            if( false !== $args['item_price'] ) {
1680
+            if (false !== $args['item_price']) {
1681 1681
                 $item_price = $args['item_price'];
1682 1682
             } else {
1683
-                $item_price = wpinv_get_item_price( $item->ID );
1683
+                $item_price = wpinv_get_item_price($item->ID);
1684 1684
             }
1685 1685
 
1686 1686
             // Sanitizing the price here so we don't have a dozen calls later
1687
-            $item_price = wpinv_sanitize_amount( $item_price );
1688
-            $subtotal   = wpinv_format_amount( $item_price * $args['quantity'], NULL, true );
1687
+            $item_price = wpinv_sanitize_amount($item_price);
1688
+            $subtotal   = wpinv_format_amount($item_price * $args['quantity'], NULL, true);
1689 1689
         
1690
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1691
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1692
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1693
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1690
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1691
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1692
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1693
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1694 1694
 
1695 1695
             // Setup the items meta item
1696 1696
             $new_item = array(
@@ -1698,28 +1698,28 @@  discard block
 block discarded – undo
1698 1698
                 'quantity' => $args['quantity'],
1699 1699
             );
1700 1700
 
1701
-            $this->items[]  = $new_item;
1701
+            $this->items[] = $new_item;
1702 1702
 
1703
-            if ( wpinv_prices_include_tax() ) {
1704
-                $subtotal -= wpinv_format_amount( $tax, NULL, true );
1703
+            if (wpinv_prices_include_tax()) {
1704
+                $subtotal -= wpinv_format_amount($tax, NULL, true);
1705 1705
             }
1706 1706
 
1707
-            $total      = $subtotal - $discount + $tax;
1707
+            $total = $subtotal - $discount + $tax;
1708 1708
 
1709 1709
             // Do not allow totals to go negative
1710
-            if( $total < 0 ) {
1710
+            if ($total < 0) {
1711 1711
                 $total = 0;
1712 1712
             }
1713 1713
         
1714 1714
             $this->cart_details[] = array(
1715 1715
                 'name'        => !empty($args['name']) ? $args['name'] : $item->get_name(),
1716 1716
                 'id'          => $item->ID,
1717
-                'item_price'  => wpinv_format_amount( $item_price, NULL, true ),
1717
+                'item_price'  => wpinv_format_amount($item_price, NULL, true),
1718 1718
                 'quantity'    => $args['quantity'],
1719 1719
                 'discount'    => $discount,
1720
-                'subtotal'    => wpinv_format_amount( $subtotal, NULL, true ),
1721
-                'tax'         => wpinv_format_amount( $tax, NULL, true ),
1722
-                'price'       => wpinv_format_amount( $total, NULL, true ),
1720
+                'subtotal'    => wpinv_format_amount($subtotal, NULL, true),
1721
+                'tax'         => wpinv_format_amount($tax, NULL, true),
1722
+                'price'       => wpinv_format_amount($total, NULL, true),
1723 1723
                 'vat_rate'    => $tax_rate,
1724 1724
                 'vat_class'   => $tax_class,
1725 1725
                 'meta'        => $args['meta'],
@@ -1729,69 +1729,69 @@  discard block
 block discarded – undo
1729 1729
             $subtotal = $subtotal - $discount;
1730 1730
         }
1731 1731
         
1732
-        $added_item = end( $this->cart_details );
1733
-        $added_item['action']  = 'add';
1732
+        $added_item = end($this->cart_details);
1733
+        $added_item['action'] = 'add';
1734 1734
         
1735 1735
         $this->pending['items'][] = $added_item;
1736 1736
         
1737
-        $this->increase_subtotal( $subtotal );
1738
-        $this->increase_tax( $tax );
1737
+        $this->increase_subtotal($subtotal);
1738
+        $this->increase_tax($tax);
1739 1739
 
1740 1740
         return true;
1741 1741
     }
1742 1742
     
1743
-    public function remove_item( $item_id, $args = array() ) {
1743
+    public function remove_item($item_id, $args = array()) {
1744 1744
         // Set some defaults
1745 1745
         $defaults = array(
1746 1746
             'quantity'   => 1,
1747 1747
             'item_price' => false,
1748 1748
             'cart_index' => false,
1749 1749
         );
1750
-        $args = wp_parse_args( $args, $defaults );
1750
+        $args = wp_parse_args($args, $defaults);
1751 1751
 
1752 1752
         // Bail if this post isn't a item
1753
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1753
+        if (get_post_type($item_id) !== 'wpi_item') {
1754 1754
             return false;
1755 1755
         }
1756 1756
         
1757
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1757
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1758 1758
 
1759
-        foreach ( $this->items as $key => $item ) {
1760
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1759
+        foreach ($this->items as $key => $item) {
1760
+            if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) {
1761 1761
                 continue;
1762 1762
             }
1763 1763
 
1764
-            if ( false !== $args['cart_index'] ) {
1765
-                $cart_index = absint( $args['cart_index'] );
1766
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
1764
+            if (false !== $args['cart_index']) {
1765
+                $cart_index = absint($args['cart_index']);
1766
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
1767 1767
 
1768
-                if ( ! empty( $cart_item ) ) {
1768
+                if (!empty($cart_item)) {
1769 1769
                     // If the cart index item isn't the same item ID, don't remove it
1770
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
1770
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
1771 1771
                         continue;
1772 1772
                     }
1773 1773
                 }
1774 1774
             }
1775 1775
 
1776
-            $item_quantity = $this->items[ $key ]['quantity'];
1777
-            if ( $item_quantity > $args['quantity'] ) {
1778
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
1776
+            $item_quantity = $this->items[$key]['quantity'];
1777
+            if ($item_quantity > $args['quantity']) {
1778
+                $this->items[$key]['quantity'] -= $args['quantity'];
1779 1779
                 break;
1780 1780
             } else {
1781
-                unset( $this->items[ $key ] );
1781
+                unset($this->items[$key]);
1782 1782
                 break;
1783 1783
             }
1784 1784
         }
1785 1785
 
1786 1786
         $found_cart_key = false;
1787
-        if ( false === $args['cart_index'] ) {
1788
-            foreach ( $this->cart_details as $cart_key => $item ) {
1789
-                if ( $item_id != $item['id'] ) {
1787
+        if (false === $args['cart_index']) {
1788
+            foreach ($this->cart_details as $cart_key => $item) {
1789
+                if ($item_id != $item['id']) {
1790 1790
                     continue;
1791 1791
                 }
1792 1792
 
1793
-                if ( false !== $args['item_price'] ) {
1794
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
1793
+                if (false !== $args['item_price']) {
1794
+                    if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) {
1795 1795
                         continue;
1796 1796
                     }
1797 1797
                 }
@@ -1800,13 +1800,13 @@  discard block
 block discarded – undo
1800 1800
                 break;
1801 1801
             }
1802 1802
         } else {
1803
-            $cart_index = absint( $args['cart_index'] );
1803
+            $cart_index = absint($args['cart_index']);
1804 1804
 
1805
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
1805
+            if (!array_key_exists($cart_index, $this->cart_details)) {
1806 1806
                 return false; // Invalid cart index passed.
1807 1807
             }
1808 1808
 
1809
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
1809
+            if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) {
1810 1810
                 return false; // We still need the proper Item ID to be sure.
1811 1811
             }
1812 1812
 
@@ -1814,41 +1814,41 @@  discard block
 block discarded – undo
1814 1814
         }
1815 1815
         
1816 1816
         $cart_item  = $this->cart_details[$found_cart_key];
1817
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1817
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1818 1818
         
1819
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
1819
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
1820 1820
             return false; // Invoice must contain at least one item.
1821 1821
         }
1822 1822
         
1823
-        $discounts  = $this->get_discounts();
1823
+        $discounts = $this->get_discounts();
1824 1824
         
1825
-        if ( $quantity > $args['quantity'] ) {
1825
+        if ($quantity > $args['quantity']) {
1826 1826
             $item_price         = $cart_item['item_price'];
1827
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1827
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1828 1828
             
1829
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
1829
+            $new_quantity       = max($quantity - $args['quantity'], 1);
1830 1830
             $subtotal           = $item_price * $new_quantity;
1831 1831
             
1832 1832
             $args['quantity']   = $new_quantity;
1833
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1834
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1833
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1834
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1835 1835
             
1836
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_format_amount( ( (float)$cart_item['discount'] / $quantity ), NULL, true ) : 0;
1836
+            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_format_amount(((float)$cart_item['discount'] / $quantity), NULL, true) : 0;
1837 1837
             $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
1838
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_format_amount( ( (float)$cart_item['tax'] / $quantity ), NULL, true ) : 0;
1838
+            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_format_amount(((float)$cart_item['tax'] / $quantity), NULL, true) : 0;
1839 1839
             $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
1840 1840
             
1841 1841
             // The total increase equals the number removed * the item_price
1842
-            $total_decrease     = wpinv_format_amount( $item_price, NULL, true );
1842
+            $total_decrease     = wpinv_format_amount($item_price, NULL, true);
1843 1843
             
1844
-            if ( wpinv_prices_include_tax() ) {
1845
-                $subtotal -= wpinv_format_amount( $tax, NULL, true );
1844
+            if (wpinv_prices_include_tax()) {
1845
+                $subtotal -= wpinv_format_amount($tax, NULL, true);
1846 1846
             }
1847 1847
 
1848
-            $total              = $subtotal - $discount + $tax;
1848
+            $total = $subtotal - $discount + $tax;
1849 1849
 
1850 1850
             // Do not allow totals to go negative
1851
-            if( $total < 0 ) {
1851
+            if ($total < 0) {
1852 1852
                 $total = 0;
1853 1853
             }
1854 1854
             
@@ -1867,16 +1867,16 @@  discard block
 block discarded – undo
1867 1867
             
1868 1868
             $this->cart_details[$found_cart_key] = $cart_item;
1869 1869
             
1870
-            $remove_item = end( $this->cart_details );
1870
+            $remove_item = end($this->cart_details);
1871 1871
         } else {
1872 1872
             $item_price     = $cart_item['item_price'];
1873
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1874
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
1873
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1874
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
1875 1875
         
1876
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
1876
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
1877 1877
             $tax_decrease       = $tax;
1878 1878
 
1879
-            unset( $this->cart_details[$found_cart_key] );
1879
+            unset($this->cart_details[$found_cart_key]);
1880 1880
             
1881 1881
             $remove_item             = $args;
1882 1882
             $remove_item['id']       = $item_id;
@@ -1887,8 +1887,8 @@  discard block
 block discarded – undo
1887 1887
         $remove_item['action']      = 'remove';
1888 1888
         $this->pending['items'][]   = $remove_item;
1889 1889
                
1890
-        $this->decrease_subtotal( $subtotal_decrease );
1891
-        $this->decrease_tax( $tax_decrease );
1890
+        $this->decrease_subtotal($subtotal_decrease);
1891
+        $this->decrease_tax($tax_decrease);
1892 1892
         
1893 1893
         return true;
1894 1894
     }
@@ -1896,7 +1896,7 @@  discard block
 block discarded – undo
1896 1896
     public function update_items($temp = false) {
1897 1897
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
1898 1898
         
1899
-        if ( !empty( $this->cart_details ) ) {
1899
+        if (!empty($this->cart_details)) {
1900 1900
             $wpi_nosave             = $temp;
1901 1901
             $cart_subtotal          = 0;
1902 1902
             $cart_discount          = 0;
@@ -1906,41 +1906,41 @@  discard block
 block discarded – undo
1906 1906
             $_POST['wpinv_country'] = $this->country;
1907 1907
             $_POST['wpinv_state']   = $this->state;
1908 1908
             
1909
-            foreach ( $this->cart_details as $key => $item ) {
1909
+            foreach ($this->cart_details as $key => $item) {
1910 1910
                 $item_price = $item['item_price'];
1911
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1912
-                $amount     = wpinv_format_amount( $item_price * $quantity, NULL, true );
1911
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1912
+                $amount     = wpinv_format_amount($item_price * $quantity, NULL, true);
1913 1913
                 $subtotal   = $item_price * $quantity;
1914 1914
                 
1915 1915
                 $wpi_current_id         = $this->ID;
1916 1916
                 $wpi_item_id            = $item['id'];
1917 1917
                 
1918
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
1918
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
1919 1919
                 
1920
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
1921
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
1922
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1920
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
1921
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
1922
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1923 1923
 
1924
-                if ( wpinv_prices_include_tax() ) {
1925
-                    $subtotal -= wpinv_format_amount( $tax, NULL, true );
1924
+                if (wpinv_prices_include_tax()) {
1925
+                    $subtotal -= wpinv_format_amount($tax, NULL, true);
1926 1926
                 }
1927 1927
 
1928
-                $total      = $subtotal - $discount + $tax;
1928
+                $total = $subtotal - $discount + $tax;
1929 1929
 
1930 1930
                 // Do not allow totals to go negative
1931
-                if( $total < 0 ) {
1931
+                if ($total < 0) {
1932 1932
                     $total = 0;
1933 1933
                 }
1934 1934
 
1935 1935
                 $cart_details[] = array(
1936 1936
                     'id'          => $item['id'],
1937 1937
                     'name'        => $item['name'],
1938
-                    'item_price'  => wpinv_format_amount( $item_price, NULL, true ),
1938
+                    'item_price'  => wpinv_format_amount($item_price, NULL, true),
1939 1939
                     'quantity'    => $quantity,
1940 1940
                     'discount'    => $discount,
1941
-                    'subtotal'    => wpinv_format_amount( $subtotal, NULL, true ),
1942
-                    'tax'         => wpinv_format_amount( $tax, NULL, true ),
1943
-                    'price'       => wpinv_format_amount( $total, NULL, true ),
1941
+                    'subtotal'    => wpinv_format_amount($subtotal, NULL, true),
1942
+                    'tax'         => wpinv_format_amount($tax, NULL, true),
1943
+                    'price'       => wpinv_format_amount($total, NULL, true),
1944 1944
                     'vat_rate'    => $tax_rate,
1945 1945
                     'vat_class'   => $tax_class,
1946 1946
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
@@ -1951,9 +1951,9 @@  discard block
 block discarded – undo
1951 1951
                 $cart_discount  += (float)($discount);
1952 1952
                 $cart_tax       += (float)($tax);
1953 1953
             }
1954
-            $this->subtotal = wpinv_format_amount( $cart_subtotal, NULL, true );
1955
-            $this->tax      = wpinv_format_amount( $cart_tax, NULL, true );
1956
-            $this->discount = wpinv_format_amount( $cart_discount, NULL, true );
1954
+            $this->subtotal = wpinv_format_amount($cart_subtotal, NULL, true);
1955
+            $this->tax      = wpinv_format_amount($cart_tax, NULL, true);
1956
+            $this->discount = wpinv_format_amount($cart_discount, NULL, true);
1957 1957
             
1958 1958
             $this->recalculate_total();
1959 1959
             
@@ -1965,221 +1965,221 @@  discard block
 block discarded – undo
1965 1965
     
1966 1966
     public function recalculate_totals($temp = false) {        
1967 1967
         $this->update_items($temp);
1968
-        $this->save( true );
1968
+        $this->save(true);
1969 1969
         
1970 1970
         return $this;
1971 1971
     }
1972 1972
     
1973 1973
     public function needs_payment() {
1974
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'pending' ), $this );
1974
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('pending'), $this);
1975 1975
 
1976
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() ) ) {
1976
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial())) {
1977 1977
             $needs_payment = true;
1978 1978
         } else {
1979 1979
             $needs_payment = false;
1980 1980
         }
1981 1981
 
1982
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
1982
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
1983 1983
     }
1984 1984
     
1985
-    public function get_checkout_payment_url( $on_checkout = false, $secret = false ) {
1985
+    public function get_checkout_payment_url($on_checkout = false, $secret = false) {
1986 1986
         $pay_url = wpinv_get_checkout_uri();
1987 1987
 
1988
-        if ( is_ssl() ) {
1989
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
1988
+        if (is_ssl()) {
1989
+            $pay_url = str_replace('http:', 'https:', $pay_url);
1990 1990
         }
1991 1991
         
1992 1992
         $key = $this->get_key();
1993 1993
 
1994
-        if ( $on_checkout ) {
1995
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
1994
+        if ($on_checkout) {
1995
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
1996 1996
         } else {
1997
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
1997
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
1998 1998
         }
1999 1999
         
2000
-        if ( $secret ) {
2001
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
2000
+        if ($secret) {
2001
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
2002 2002
         }
2003 2003
 
2004
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this );
2004
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this);
2005 2005
     }
2006 2006
     
2007
-    public function get_view_url( $secret = false ) {
2008
-        $print_url = get_permalink( $this->ID );
2007
+    public function get_view_url($secret = false) {
2008
+        $print_url = get_permalink($this->ID);
2009 2009
         
2010
-        if ( $secret ) {
2011
-            $print_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $print_url );
2010
+        if ($secret) {
2011
+            $print_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $print_url);
2012 2012
         }
2013 2013
 
2014
-        return apply_filters( 'wpinv_get_view_url', $print_url, $this );
2014
+        return apply_filters('wpinv_get_view_url', $print_url, $this);
2015 2015
     }
2016 2016
     
2017
-    public function generate_key( $string = '' ) {
2018
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2019
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2017
+    public function generate_key($string = '') {
2018
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2019
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2020 2020
     }
2021 2021
     
2022 2022
     public function is_recurring() {
2023
-        if ( empty( $this->cart_details ) ) {
2023
+        if (empty($this->cart_details)) {
2024 2024
             return false;
2025 2025
         }
2026 2026
         
2027 2027
         $has_subscription = false;
2028
-        foreach( $this->cart_details as $cart_item ) {
2029
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2028
+        foreach ($this->cart_details as $cart_item) {
2029
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2030 2030
                 $has_subscription = true;
2031 2031
                 break;
2032 2032
             }
2033 2033
         }
2034 2034
         
2035
-        if ( count( $this->cart_details ) > 1 ) {
2035
+        if (count($this->cart_details) > 1) {
2036 2036
             $has_subscription = false;
2037 2037
         }
2038 2038
 
2039
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2039
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2040 2040
     }
2041 2041
     
2042 2042
     public function is_free_trial() {
2043 2043
         $is_free_trial = false;
2044 2044
         
2045
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2046
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2045
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2046
+            if (!empty($item) && $item->has_free_trial()) {
2047 2047
                 $is_free_trial = true;
2048 2048
             }
2049 2049
         }
2050 2050
 
2051
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details );
2051
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details);
2052 2052
     }
2053 2053
     
2054
-    public function get_recurring( $object = false ) {
2054
+    public function get_recurring($object = false) {
2055 2055
         $item = NULL;
2056 2056
         
2057
-        if ( empty( $this->cart_details ) ) {
2057
+        if (empty($this->cart_details)) {
2058 2058
             return $item;
2059 2059
         }
2060 2060
         
2061
-        foreach( $this->cart_details as $cart_item ) {
2062
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2061
+        foreach ($this->cart_details as $cart_item) {
2062
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2063 2063
                 $item = $cart_item['id'];
2064 2064
                 break;
2065 2065
             }
2066 2066
         }
2067 2067
         
2068
-        if ( $object ) {
2069
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2068
+        if ($object) {
2069
+            $item = $item ? new WPInv_Item($item) : NULL;
2070 2070
             
2071
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2071
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2072 2072
         }
2073 2073
 
2074
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2074
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2075 2075
     }
2076 2076
     
2077 2077
     public function get_subscription_name() {
2078
-        $item = $this->get_recurring( true );
2078
+        $item = $this->get_recurring(true);
2079 2079
         
2080
-        if ( empty( $item ) ) {
2080
+        if (empty($item)) {
2081 2081
             return NULL;
2082 2082
         }
2083 2083
         
2084
-        if ( !($name = $item->get_name()) ) {
2084
+        if (!($name = $item->get_name())) {
2085 2085
             $name = $item->post_name;
2086 2086
         }
2087 2087
 
2088
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2088
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2089 2089
     }
2090 2090
         
2091 2091
     public function get_expiration() {
2092
-        $expiration = $this->get_meta( '_wpinv_subscr_expiration', true );
2092
+        $expiration = $this->get_meta('_wpinv_subscr_expiration', true);
2093 2093
         return $expiration;
2094 2094
     }
2095 2095
     
2096
-    public function get_cancelled_date( $formatted = true ) {
2097
-        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta( '_wpinv_subscr_cancelled_on', true ) : '';
2096
+    public function get_cancelled_date($formatted = true) {
2097
+        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta('_wpinv_subscr_cancelled_on', true) : '';
2098 2098
         
2099
-        if ( $formatted && $cancelled_date ) {
2100
-            $cancelled_date = date_i18n( get_option( 'date_format' ), strtotime( $cancelled_date ) );
2099
+        if ($formatted && $cancelled_date) {
2100
+            $cancelled_date = date_i18n(get_option('date_format'), strtotime($cancelled_date));
2101 2101
         }
2102 2102
         
2103 2103
         return $cancelled_date;
2104 2104
     }
2105 2105
     
2106
-    public function get_trial_end_date( $formatted = true ) {
2107
-        if ( !$this->is_free_trial() || !$this->is_paid() ) {
2106
+    public function get_trial_end_date($formatted = true) {
2107
+        if (!$this->is_free_trial() || !$this->is_paid()) {
2108 2108
             return NULL;
2109 2109
         }
2110 2110
         
2111
-        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta( '_wpinv_subscr_trial_end', true ) : '';
2111
+        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta('_wpinv_subscr_trial_end', true) : '';
2112 2112
         
2113
-        if ( empty( $trial_end_date ) ) {
2114
-            $trial_start_time = strtotime( $this->get_subscription_start() );
2115
-            $trial_start_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2113
+        if (empty($trial_end_date)) {
2114
+            $trial_start_time = strtotime($this->get_subscription_start());
2115
+            $trial_start_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2116 2116
             
2117
-            $trial_end_date = date_i18n( 'Y-m-d H:i:s', $trial_start_time );
2117
+            $trial_end_date = date_i18n('Y-m-d H:i:s', $trial_start_time);
2118 2118
         }
2119 2119
         
2120
-        if ( $formatted && $trial_end_date ) {
2121
-            $trial_end_date = date_i18n( get_option( 'date_format' ), strtotime( $trial_end_date ) );
2120
+        if ($formatted && $trial_end_date) {
2121
+            $trial_end_date = date_i18n(get_option('date_format'), strtotime($trial_end_date));
2122 2122
         }
2123 2123
         
2124 2124
         return $trial_end_date;
2125 2125
     }
2126 2126
     
2127
-    public function get_subscription_created( $default = true ) {
2128
-        $created = $this->get_meta( '_wpinv_subscr_created', true );
2127
+    public function get_subscription_created($default = true) {
2128
+        $created = $this->get_meta('_wpinv_subscr_created', true);
2129 2129
         
2130
-        if ( empty( $created ) && $default ) {
2130
+        if (empty($created) && $default) {
2131 2131
             $created = $this->date;
2132 2132
         }
2133 2133
         return $created;
2134 2134
     }
2135 2135
     
2136
-    public function get_subscription_start( $formatted = true ) {
2137
-        if ( !$this->is_paid() ) {
2136
+    public function get_subscription_start($formatted = true) {
2137
+        if (!$this->is_paid()) {
2138 2138
             return '-';
2139 2139
         }
2140
-        $start   = $this->get_subscription_created();
2140
+        $start = $this->get_subscription_created();
2141 2141
         
2142
-        if ( $formatted ) {
2143
-            $date = date_i18n( get_option( 'date_format' ), strtotime( $start ) );
2142
+        if ($formatted) {
2143
+            $date = date_i18n(get_option('date_format'), strtotime($start));
2144 2144
         } else {
2145
-            $date = date_i18n( 'Y-m-d H:i:s', strtotime( $start ) );
2145
+            $date = date_i18n('Y-m-d H:i:s', strtotime($start));
2146 2146
         }
2147 2147
 
2148 2148
         return $date;
2149 2149
     }
2150 2150
     
2151
-    public function get_subscription_end( $formatted = true ) {
2152
-        if ( !$this->is_paid() ) {
2151
+    public function get_subscription_end($formatted = true) {
2152
+        if (!$this->is_paid()) {
2153 2153
             return '-';
2154 2154
         }
2155 2155
         $start          = $this->get_subscription_created();
2156 2156
         $interval       = $this->get_subscription_interval();
2157
-        $period         = $this->get_subscription_period( true );
2157
+        $period         = $this->get_subscription_period(true);
2158 2158
         $bill_times     = (int)$this->get_bill_times();
2159 2159
         
2160
-        if ( $bill_times == 0 ) {
2161
-            return $formatted ? __( 'Until cancelled', 'invoicing' ) : $bill_times;
2160
+        if ($bill_times == 0) {
2161
+            return $formatted ? __('Until cancelled', 'invoicing') : $bill_times;
2162 2162
         }
2163 2163
         
2164
-        $total_period = $start . '+' . ( $interval * $bill_times ) . ' ' . $period;
2164
+        $total_period = $start . '+' . ($interval * $bill_times) . ' ' . $period;
2165 2165
         
2166
-        $end_time = strtotime( $start . '+' . ( $interval * $bill_times ) . ' ' . $period );
2166
+        $end_time = strtotime($start . '+' . ($interval * $bill_times) . ' ' . $period);
2167 2167
         
2168
-        if ( $this->is_free_trial() ) {
2169
-            $end_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2168
+        if ($this->is_free_trial()) {
2169
+            $end_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2170 2170
         }
2171 2171
         
2172
-        if ( $formatted ) {
2173
-            $date = date_i18n( get_option( 'date_format' ), $end_time );
2172
+        if ($formatted) {
2173
+            $date = date_i18n(get_option('date_format'), $end_time);
2174 2174
         } else {
2175
-            $date = date_i18n( 'Y-m-d H:i:s', $end_time );
2175
+            $date = date_i18n('Y-m-d H:i:s', $end_time);
2176 2176
         }
2177 2177
 
2178 2178
         return $date;
2179 2179
     }
2180 2180
     
2181 2181
     public function get_expiration_time() {
2182
-        return strtotime( $this->get_expiration(), current_time( 'timestamp' ) );
2182
+        return strtotime($this->get_expiration(), current_time('timestamp'));
2183 2183
     }
2184 2184
     
2185 2185
     public function get_original_invoice_id() {        
@@ -2191,125 +2191,125 @@  discard block
 block discarded – undo
2191 2191
         return $subscription_data['bill_times'];
2192 2192
     }
2193 2193
 
2194
-    public function get_child_payments( $self = false ) {
2195
-        $invoices = get_posts( array(
2194
+    public function get_child_payments($self = false) {
2195
+        $invoices = get_posts(array(
2196 2196
             'post_type'         => 'wpi_invoice',
2197 2197
             'post_parent'       => (int)$this->ID,
2198 2198
             'posts_per_page'    => '999',
2199
-            'post_status'       => array( 'publish', 'complete', 'processing', 'renewal' ),
2199
+            'post_status'       => array('publish', 'complete', 'processing', 'renewal'),
2200 2200
             'orderby'           => 'ID',
2201 2201
             'order'             => 'DESC',
2202 2202
             'fields'            => 'ids'
2203
-        ) );
2203
+        ));
2204 2204
         
2205
-        if ( $this->is_free_trial() ) {
2205
+        if ($this->is_free_trial()) {
2206 2206
             $self = false;
2207 2207
         }
2208 2208
         
2209
-        if ( $self && $this->is_paid() ) {
2210
-            if ( !empty( $invoices ) ) {
2209
+        if ($self && $this->is_paid()) {
2210
+            if (!empty($invoices)) {
2211 2211
                 $invoices[] = (int)$this->ID;
2212 2212
             } else {
2213
-                $invoices = array( $this->ID );
2213
+                $invoices = array($this->ID);
2214 2214
             }
2215 2215
             
2216
-            $invoices = array_unique( $invoices );
2216
+            $invoices = array_unique($invoices);
2217 2217
         }
2218 2218
 
2219 2219
         return $invoices;
2220 2220
     }
2221 2221
 
2222
-    public function get_total_payments( $self = true ) {
2223
-        return count( $this->get_child_payments( $self ) );
2222
+    public function get_total_payments($self = true) {
2223
+        return count($this->get_child_payments($self));
2224 2224
     }
2225 2225
     
2226
-    public function get_subscriptions( $limit = -1 ) {
2227
-        $subscriptions = wpinv_get_subscriptions( array( 'parent_invoice_id' => $this->ID, 'numberposts' => $limit ) );
2226
+    public function get_subscriptions($limit = -1) {
2227
+        $subscriptions = wpinv_get_subscriptions(array('parent_invoice_id' => $this->ID, 'numberposts' => $limit));
2228 2228
 
2229 2229
         return $subscriptions;
2230 2230
     }
2231 2231
     
2232 2232
     public function get_subscription_id() {
2233
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2233
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2234 2234
         
2235
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2236
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2235
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2236
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2237 2237
             
2238
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2238
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2239 2239
         }
2240 2240
         
2241 2241
         return $subscription_id;
2242 2242
     }
2243 2243
     
2244 2244
     public function get_subscription_status() {
2245
-        $subscription_status = $this->get_meta( '_wpinv_subscr_status', true );
2245
+        $subscription_status = $this->get_meta('_wpinv_subscr_status', true);
2246 2246
 
2247
-        if ( empty( $subscription_status ) ) {
2247
+        if (empty($subscription_status)) {
2248 2248
             $status = 'pending';
2249 2249
             
2250
-            if ( $this->is_paid() ) {        
2250
+            if ($this->is_paid()) {        
2251 2251
                 $bill_times   = (int)$this->get_bill_times();
2252 2252
                 $times_billed = (int)$this->get_total_payments();
2253
-                $expiration = $this->get_subscription_end( false );
2254
-                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime( date_i18n( 'Y-m-d', strtotime( $expiration ) ) ) < strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ) ? true : false;
2253
+                $expiration = $this->get_subscription_end(false);
2254
+                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime(date_i18n('Y-m-d', strtotime($expiration))) < strtotime(date_i18n('Y-m-d', current_time('timestamp'))) ? true : false;
2255 2255
                 
2256
-                if ( (int)$bill_times == 0 ) {
2256
+                if ((int)$bill_times == 0) {
2257 2257
                     $status = $expired ? 'expired' : 'active';
2258
-                } else if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2258
+                } else if ($bill_times > 0 && $times_billed >= $bill_times) {
2259 2259
                     $status = 'completed';
2260
-                } else if ( $expired ) {
2260
+                } else if ($expired) {
2261 2261
                     $status = 'expired';
2262
-                } else if ( $bill_times > 0 ) {
2262
+                } else if ($bill_times > 0) {
2263 2263
                     $status = 'active';
2264 2264
                 } else {
2265 2265
                     $status = 'pending';
2266 2266
                 }
2267 2267
             }
2268 2268
             
2269
-            if ( $status && $status != $subscription_status ) {
2269
+            if ($status && $status != $subscription_status) {
2270 2270
                 $subscription_status = $status;
2271 2271
                 
2272
-                $this->update_meta( '_wpinv_subscr_status', $status );
2272
+                $this->update_meta('_wpinv_subscr_status', $status);
2273 2273
             }
2274 2274
         }
2275 2275
         
2276 2276
         return $subscription_status;
2277 2277
     }
2278 2278
     
2279
-    public function get_subscription_status_label( $status = '' ) {
2280
-        $status = !empty( $status ) ? $status : $this->get_subscription_status();
2279
+    public function get_subscription_status_label($status = '') {
2280
+        $status = !empty($status) ? $status : $this->get_subscription_status();
2281 2281
 
2282
-        switch( $status ) {
2282
+        switch ($status) {
2283 2283
             case 'active' :
2284
-                $status_label = __( 'Active', 'invoicing' );
2284
+                $status_label = __('Active', 'invoicing');
2285 2285
                 break;
2286 2286
 
2287 2287
             case 'cancelled' :
2288
-                $status_label = __( 'Cancelled', 'invoicing' );
2288
+                $status_label = __('Cancelled', 'invoicing');
2289 2289
                 break;
2290 2290
                 
2291 2291
             case 'completed' :
2292
-                $status_label = __( 'Completed', 'invoicing' );
2292
+                $status_label = __('Completed', 'invoicing');
2293 2293
                 break;
2294 2294
 
2295 2295
             case 'expired' :
2296
-                $status_label = __( 'Expired', 'invoicing' );
2296
+                $status_label = __('Expired', 'invoicing');
2297 2297
                 break;
2298 2298
 
2299 2299
             case 'pending' :
2300
-                $status_label = __( 'Pending', 'invoicing' );
2300
+                $status_label = __('Pending', 'invoicing');
2301 2301
                 break;
2302 2302
 
2303 2303
             case 'failing' :
2304
-                $status_label = __( 'Failing', 'invoicing' );
2304
+                $status_label = __('Failing', 'invoicing');
2305 2305
                 break;
2306 2306
                 
2307 2307
             case 'stopped' :
2308
-                $status_label = __( 'Stopped', 'invoicing' );
2308
+                $status_label = __('Stopped', 'invoicing');
2309 2309
                 break;
2310 2310
                 
2311 2311
             case 'trialing' :
2312
-                $status_label = __( 'Trialing', 'invoicing' );
2312
+                $status_label = __('Trialing', 'invoicing');
2313 2313
                 break;
2314 2314
 
2315 2315
             default:
@@ -2320,15 +2320,15 @@  discard block
 block discarded – undo
2320 2320
         return $status_label;
2321 2321
     }
2322 2322
     
2323
-    public function get_subscription_period( $full = false ) {
2324
-        $period = $this->get_meta( '_wpinv_subscr_period', true );
2323
+    public function get_subscription_period($full = false) {
2324
+        $period = $this->get_meta('_wpinv_subscr_period', true);
2325 2325
         
2326
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2326
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2327 2327
             $period = 'D';
2328 2328
         }
2329 2329
         
2330
-        if ( $full ) {
2331
-            switch( $period ) {
2330
+        if ($full) {
2331
+            switch ($period) {
2332 2332
                 case 'D':
2333 2333
                     $period = 'day';
2334 2334
                 break;
@@ -2348,28 +2348,28 @@  discard block
 block discarded – undo
2348 2348
     }
2349 2349
     
2350 2350
     public function get_subscription_interval() {
2351
-        $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true );
2351
+        $interval = (int)$this->get_meta('_wpinv_subscr_interval', true);
2352 2352
         
2353
-        if ( !$interval > 0 ) {
2353
+        if (!$interval > 0) {
2354 2354
             $interval = 1;
2355 2355
         }
2356 2356
         
2357 2357
         return $interval;
2358 2358
     }
2359 2359
     
2360
-    public function get_subscription_trial_period( $full = false ) {
2361
-        if ( !$this->is_free_trial() ) {
2360
+    public function get_subscription_trial_period($full = false) {
2361
+        if (!$this->is_free_trial()) {
2362 2362
             return '';
2363 2363
         }
2364 2364
         
2365
-        $period = $this->get_meta( '_wpinv_subscr_trial_period', true );
2365
+        $period = $this->get_meta('_wpinv_subscr_trial_period', true);
2366 2366
         
2367
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2367
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2368 2368
             $period = 'D';
2369 2369
         }
2370 2370
         
2371
-        if ( $full ) {
2372
-            switch( $period ) {
2371
+        if ($full) {
2372
+            switch ($period) {
2373 2373
                 case 'D':
2374 2374
                     $period = 'day';
2375 2375
                 break;
@@ -2389,13 +2389,13 @@  discard block
 block discarded – undo
2389 2389
     }
2390 2390
     
2391 2391
     public function get_subscription_trial_interval() {
2392
-        if ( !$this->is_free_trial() ) {
2392
+        if (!$this->is_free_trial()) {
2393 2393
             return 0;
2394 2394
         }
2395 2395
         
2396
-        $interval = (int)$this->get_meta( '_wpinv_subscr_trial_interval', true );
2396
+        $interval = (int)$this->get_meta('_wpinv_subscr_trial_interval', true);
2397 2397
         
2398
-        if ( !$interval > 0 ) {
2398
+        if (!$interval > 0) {
2399 2399
             $interval = 1;
2400 2400
         }
2401 2401
         
@@ -2407,8 +2407,8 @@  discard block
 block discarded – undo
2407 2407
             'status' => 'failing'
2408 2408
         );
2409 2409
 
2410
-        if ( $this->update_subscription( $args ) ) {
2411
-            do_action( 'wpinv_subscription_failing', $this->ID, $this );
2410
+        if ($this->update_subscription($args)) {
2411
+            do_action('wpinv_subscription_failing', $this->ID, $this);
2412 2412
             return true;
2413 2413
         }
2414 2414
 
@@ -2420,8 +2420,8 @@  discard block
 block discarded – undo
2420 2420
             'status' => 'stopped'
2421 2421
         );
2422 2422
 
2423
-        if ( $this->update_subscription( $args ) ) {
2424
-            do_action( 'wpinv_subscription_stopped', $this->ID, $this );
2423
+        if ($this->update_subscription($args)) {
2424
+            do_action('wpinv_subscription_stopped', $this->ID, $this);
2425 2425
             return true;
2426 2426
         }
2427 2427
 
@@ -2433,8 +2433,8 @@  discard block
 block discarded – undo
2433 2433
             'status' => 'active'
2434 2434
         );
2435 2435
 
2436
-        if ( $this->update_subscription( $args ) ) {
2437
-            do_action( 'wpinv_subscription_restarted', $this->ID, $this );
2436
+        if ($this->update_subscription($args)) {
2437
+            do_action('wpinv_subscription_restarted', $this->ID, $this);
2438 2438
             return true;
2439 2439
         }
2440 2440
 
@@ -2446,23 +2446,23 @@  discard block
 block discarded – undo
2446 2446
             'status' => 'cancelled'
2447 2447
         );
2448 2448
 
2449
-        if ( $this->update_subscription( $args ) ) {
2450
-            if ( is_user_logged_in() ) {
2451
-                $userdata = get_userdata( get_current_user_id() );
2449
+        if ($this->update_subscription($args)) {
2450
+            if (is_user_logged_in()) {
2451
+                $userdata = get_userdata(get_current_user_id());
2452 2452
                 $user     = $userdata->user_login;
2453 2453
             } else {
2454
-                $user = __( 'gateway', 'invoicing' );
2454
+                $user = __('gateway', 'invoicing');
2455 2455
             }
2456 2456
             
2457 2457
             $subscription_id = $this->get_subscription_id();
2458
-            if ( !$subscription_id ) {
2458
+            if (!$subscription_id) {
2459 2459
                 $subscription_id = $this->ID;
2460 2460
             }
2461 2461
 
2462
-            $note = sprintf( __( 'Subscription %s has been cancelled by %s', 'invoicing' ), $subscription_id, $user );
2463
-            $this->add_note( $note );
2462
+            $note = sprintf(__('Subscription %s has been cancelled by %s', 'invoicing'), $subscription_id, $user);
2463
+            $this->add_note($note);
2464 2464
 
2465
-            do_action( 'wpinv_subscription_cancelled', $this->ID, $this );
2465
+            do_action('wpinv_subscription_cancelled', $this->ID, $this);
2466 2466
             return true;
2467 2467
         }
2468 2468
 
@@ -2470,11 +2470,11 @@  discard block
 block discarded – undo
2470 2470
     }
2471 2471
 
2472 2472
     public function can_cancel() {
2473
-        return apply_filters( 'wpinv_subscription_can_cancel', false, $this );
2473
+        return apply_filters('wpinv_subscription_can_cancel', false, $this);
2474 2474
     }
2475 2475
     
2476
-    public function add_subscription( $data = array() ) {
2477
-        if ( empty( $this->ID ) ) {
2476
+    public function add_subscription($data = array()) {
2477
+        if (empty($this->ID)) {
2478 2478
             return false;
2479 2479
         }
2480 2480
 
@@ -2493,85 +2493,85 @@  discard block
 block discarded – undo
2493 2493
             'profile_id'        => '',
2494 2494
         );
2495 2495
 
2496
-        $args = wp_parse_args( $data, $defaults );
2496
+        $args = wp_parse_args($data, $defaults);
2497 2497
 
2498
-        if ( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2499
-            if ( 'active' == $args['status'] || $args['status'] == 'trialing' ) {
2498
+        if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2499
+            if ('active' == $args['status'] || $args['status'] == 'trialing') {
2500 2500
                 $args['status'] = 'expired';
2501 2501
             }
2502 2502
         }
2503 2503
 
2504
-        do_action( 'wpinv_subscription_pre_create', $args, $data, $this );
2504
+        do_action('wpinv_subscription_pre_create', $args, $data, $this);
2505 2505
         
2506
-        if ( !empty( $args ) ) {
2507
-            foreach ( $args as $key => $value ) {
2508
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2506
+        if (!empty($args)) {
2507
+            foreach ($args as $key => $value) {
2508
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2509 2509
             }
2510 2510
         }
2511 2511
 
2512
-        do_action( 'wpinv_subscription_post_create', $args, $data, $this );
2512
+        do_action('wpinv_subscription_post_create', $args, $data, $this);
2513 2513
 
2514 2514
         return true;
2515 2515
     }
2516 2516
     
2517
-    public function update_subscription( $args = array() ) {
2518
-        if ( empty( $this->ID ) ) {
2517
+    public function update_subscription($args = array()) {
2518
+        if (empty($this->ID)) {
2519 2519
             return false;
2520 2520
         }
2521 2521
 
2522
-        if ( !empty( $args['expiration'] ) && $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2523
-            if ( !isset( $args['status'] ) || ( isset( $args['status'] ) && ( 'active' == $args['status'] || $args['status'] == 'trialing' ) ) ) {
2522
+        if (!empty($args['expiration']) && $args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2523
+            if (!isset($args['status']) || (isset($args['status']) && ('active' == $args['status'] || $args['status'] == 'trialing'))) {
2524 2524
                 $args['status'] = 'expired';
2525 2525
             }
2526 2526
         }
2527 2527
 
2528
-        if ( isset( $args['status'] ) && $args['status'] == 'cancelled' && empty( $args['cancelled_on'] ) ) {
2529
-            $args['cancelled_on'] = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
2528
+        if (isset($args['status']) && $args['status'] == 'cancelled' && empty($args['cancelled_on'])) {
2529
+            $args['cancelled_on'] = date_i18n('Y-m-d H:i:s', current_time('timestamp'));
2530 2530
         }
2531 2531
 
2532
-        do_action( 'wpinv_subscription_pre_update', $args, $this );
2532
+        do_action('wpinv_subscription_pre_update', $args, $this);
2533 2533
         
2534
-        if ( !empty( $args ) ) {
2535
-            foreach ( $args as $key => $value ) {
2536
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2534
+        if (!empty($args)) {
2535
+            foreach ($args as $key => $value) {
2536
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2537 2537
             }
2538 2538
         }
2539 2539
 
2540
-        do_action( 'wpinv_subscription_post_update', $args, $this );
2540
+        do_action('wpinv_subscription_post_update', $args, $this);
2541 2541
 
2542 2542
         return true;
2543 2543
     }
2544 2544
     
2545 2545
     public function renew_subscription() {
2546 2546
         $parent_invoice = $this->get_parent_payment();
2547
-        $parent_invoice = empty( $parent_invoice ) ? $this : $parent_invoice;
2547
+        $parent_invoice = empty($parent_invoice) ? $this : $parent_invoice;
2548 2548
         
2549
-        $current_time   = current_time( 'timestamp' );
2549
+        $current_time   = current_time('timestamp');
2550 2550
         $start          = $this->get_subscription_created();
2551
-        $start          = $start ? strtotime( $start ) : $current_time;
2551
+        $start          = $start ? strtotime($start) : $current_time;
2552 2552
         $expires        = $this->get_expiration_time();
2553 2553
         
2554
-        if ( !$expires ) {
2555
-            $expires    = strtotime( '+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period( true ), $start );
2554
+        if (!$expires) {
2555
+            $expires    = strtotime('+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period(true), $start);
2556 2556
         }
2557 2557
         
2558
-        $expiration     = date_i18n( 'Y-m-d 23:59:59', $expires );
2559
-        $expiration     = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this );
2558
+        $expiration     = date_i18n('Y-m-d 23:59:59', $expires);
2559
+        $expiration     = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this);
2560 2560
         $bill_times     = $parent_invoice->get_bill_times();
2561 2561
         $times_billed   = $parent_invoice->get_total_payments();
2562 2562
         
2563
-        if ( $parent_invoice->get_subscription_status() == 'trialing' && ( $times_billed > 0 || strtotime( date_i18n( 'Y-m-d' ) ) < strtotime( $parent_invoice->get_trial_end_date( false ) ) ) ) {
2563
+        if ($parent_invoice->get_subscription_status() == 'trialing' && ($times_billed > 0 || strtotime(date_i18n('Y-m-d')) < strtotime($parent_invoice->get_trial_end_date(false)))) {
2564 2564
             $args = array(
2565 2565
                 'status'     => 'active',
2566 2566
             );
2567 2567
 
2568
-            $parent_invoice->update_subscription( $args );
2568
+            $parent_invoice->update_subscription($args);
2569 2569
         }
2570 2570
         
2571
-        do_action( 'wpinv_subscription_pre_renew', $this->ID, $expiration, $this );
2571
+        do_action('wpinv_subscription_pre_renew', $this->ID, $expiration, $this);
2572 2572
 
2573
-        $status       = 'active';
2574
-        if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2573
+        $status = 'active';
2574
+        if ($bill_times > 0 && $times_billed >= $bill_times) {
2575 2575
             $this->complete_subscription();
2576 2576
             $status = 'completed';
2577 2577
         }
@@ -2581,10 +2581,10 @@  discard block
 block discarded – undo
2581 2581
             'status'     => $status,
2582 2582
         );
2583 2583
 
2584
-        $this->update_subscription( $args );
2584
+        $this->update_subscription($args);
2585 2585
 
2586
-        do_action( 'wpinv_subscription_post_renew', $this->ID, $expiration, $this );
2587
-        do_action( 'wpinv_recurring_set_subscription_status', $this->ID, $status, $this );
2586
+        do_action('wpinv_subscription_post_renew', $this->ID, $expiration, $this);
2587
+        do_action('wpinv_recurring_set_subscription_status', $this->ID, $status, $this);
2588 2588
     }
2589 2589
     
2590 2590
     public function complete_subscription() {
@@ -2592,8 +2592,8 @@  discard block
 block discarded – undo
2592 2592
             'status' => 'completed'
2593 2593
         );
2594 2594
 
2595
-        if ( $this->update_subscription( $args ) ) {
2596
-            do_action( 'wpinv_subscription_completed', $this->ID, $this );
2595
+        if ($this->update_subscription($args)) {
2596
+            do_action('wpinv_subscription_completed', $this->ID, $this);
2597 2597
         }
2598 2598
     }
2599 2599
     
@@ -2602,44 +2602,44 @@  discard block
 block discarded – undo
2602 2602
             'status' => 'expired'
2603 2603
         );
2604 2604
 
2605
-        if ( $this->update_subscription( $args ) ) {
2606
-            do_action( 'wpinv_subscription_expired', $this->ID, $this );
2605
+        if ($this->update_subscription($args)) {
2606
+            do_action('wpinv_subscription_expired', $this->ID, $this);
2607 2607
         }
2608 2608
     }
2609 2609
 
2610 2610
     public function get_cancel_url() {
2611
-        $url = wp_nonce_url( add_query_arg( array( 'wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID ) ), 'wpinv-recurring-cancel' );
2611
+        $url = wp_nonce_url(add_query_arg(array('wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID)), 'wpinv-recurring-cancel');
2612 2612
 
2613
-        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
2613
+        return apply_filters('wpinv_subscription_cancel_url', $url, $this);
2614 2614
     }
2615 2615
 
2616 2616
     public function can_update() {
2617
-        return apply_filters( 'wpinv_subscription_can_update', false, $this );
2617
+        return apply_filters('wpinv_subscription_can_update', false, $this);
2618 2618
     }
2619 2619
 
2620 2620
     public function get_update_url() {
2621
-        $url = add_query_arg( array( 'action' => 'update', 'sub_id' => $this->ID ) );
2621
+        $url = add_query_arg(array('action' => 'update', 'sub_id' => $this->ID));
2622 2622
 
2623
-        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
2623
+        return apply_filters('wpinv_subscription_update_url', $url, $this);
2624 2624
     }
2625 2625
 
2626 2626
     public function is_parent() {
2627
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2627
+        $is_parent = empty($this->parent_invoice) ? true : false;
2628 2628
 
2629
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2629
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2630 2630
     }
2631 2631
     
2632 2632
     public function is_renewal() {
2633 2633
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2634 2634
 
2635
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2635
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2636 2636
     }
2637 2637
     
2638 2638
     public function get_parent_payment() {
2639 2639
         $parent_payment = NULL;
2640 2640
         
2641
-        if ( $this->is_renewal() ) {
2642
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2641
+        if ($this->is_renewal()) {
2642
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2643 2643
         }
2644 2644
         
2645 2645
         return $parent_payment;
@@ -2650,100 +2650,100 @@  discard block
 block discarded – undo
2650 2650
         
2651 2651
         $subscription_status = $this->get_subscription_status();
2652 2652
 
2653
-        if( ! $this->is_subscription_expired() && ( $subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing' ) ) {
2653
+        if (!$this->is_subscription_expired() && ($subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing')) {
2654 2654
             $ret = true;
2655 2655
         }
2656 2656
 
2657
-        return apply_filters( 'wpinv_subscription_is_active', $ret, $this->ID, $this );
2657
+        return apply_filters('wpinv_subscription_is_active', $ret, $this->ID, $this);
2658 2658
     }
2659 2659
 
2660 2660
     public function is_subscription_expired() {
2661 2661
         $ret = false;
2662 2662
         $subscription_status = $this->get_subscription_status();
2663 2663
 
2664
-        if ( $subscription_status == 'expired' ) {
2664
+        if ($subscription_status == 'expired') {
2665 2665
             $ret = true;
2666
-        } else if ( 'active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status ) {
2666
+        } else if ('active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status) {
2667 2667
             $ret        = false;
2668 2668
             $expiration = $this->get_expiration_time();
2669 2669
 
2670
-            if ( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) {
2670
+            if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) {
2671 2671
                 $ret = true;
2672 2672
 
2673
-                if ( 'active' === $subscription_status || 'trialing' === $subscription_status ) {
2673
+                if ('active' === $subscription_status || 'trialing' === $subscription_status) {
2674 2674
                     $this->expire_subscription();
2675 2675
                 }
2676 2676
             }
2677 2677
         }
2678 2678
 
2679
-        return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->ID, $this );
2679
+        return apply_filters('wpinv_subscription_is_expired', $ret, $this->ID, $this);
2680 2680
     }
2681 2681
     
2682
-    public function get_new_expiration( $item_id = 0, $trial = true ) {
2683
-        $item   = new WPInv_Item( $item_id );
2682
+    public function get_new_expiration($item_id = 0, $trial = true) {
2683
+        $item   = new WPInv_Item($item_id);
2684 2684
         $interval = $item->get_recurring_interval();
2685
-        $period = $item->get_recurring_period( true );
2685
+        $period = $item->get_recurring_period(true);
2686 2686
         
2687
-        $expiration_time = strtotime( '+' . $interval . ' ' . $period );
2687
+        $expiration_time = strtotime('+' . $interval . ' ' . $period);
2688 2688
         
2689
-        if ( $trial && $this->is_free_trial() && $item->has_free_trial() ) {
2690
-            $expiration_time += ( wpinv_period_in_days( $item->get_trial_interval(), $item->get_trial_period() ) * DAY_IN_SECONDS ) ;
2689
+        if ($trial && $this->is_free_trial() && $item->has_free_trial()) {
2690
+            $expiration_time += (wpinv_period_in_days($item->get_trial_interval(), $item->get_trial_period()) * DAY_IN_SECONDS);
2691 2691
         }
2692 2692
 
2693
-        return date_i18n( 'Y-m-d 23:59:59', $expiration_time );
2693
+        return date_i18n('Y-m-d 23:59:59', $expiration_time);
2694 2694
     }
2695 2695
     
2696
-    public function get_subscription_data( $filed = '' ) {
2697
-        $fields = array( 'item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on' );
2696
+    public function get_subscription_data($filed = '') {
2697
+        $fields = array('item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on');
2698 2698
         
2699 2699
         $subscription_meta = array();
2700
-        foreach ( $fields as $field ) {
2701
-            $subscription_meta[ $field ] = $this->get_meta( '_wpinv_subscr_' . $field, true );
2700
+        foreach ($fields as $field) {
2701
+            $subscription_meta[$field] = $this->get_meta('_wpinv_subscr_' . $field, true);
2702 2702
         }
2703 2703
         
2704
-        $item = $this->get_recurring( true );
2704
+        $item = $this->get_recurring(true);
2705 2705
         
2706
-        if ( !empty( $item ) ) {
2707
-            if ( empty( $subscription_meta['item_id'] ) ) {
2706
+        if (!empty($item)) {
2707
+            if (empty($subscription_meta['item_id'])) {
2708 2708
                 $subscription_meta['item_id'] = $item->ID;
2709 2709
             }
2710
-            if ( empty( $subscription_meta['period'] ) ) {
2710
+            if (empty($subscription_meta['period'])) {
2711 2711
                 $subscription_meta['period'] = $item->get_recurring_period();
2712 2712
             }
2713
-            if ( empty( $subscription_meta['interval'] ) ) {
2713
+            if (empty($subscription_meta['interval'])) {
2714 2714
                 $subscription_meta['interval'] = $item->get_recurring_interval();
2715 2715
             }
2716
-            if ( $item->has_free_trial() ) {
2717
-                if ( empty( $subscription_meta['trial_period'] ) ) {
2716
+            if ($item->has_free_trial()) {
2717
+                if (empty($subscription_meta['trial_period'])) {
2718 2718
                     $subscription_meta['trial_period'] = $item->get_trial_period();
2719 2719
                 }
2720
-                if ( empty( $subscription_meta['trial_interval'] ) ) {
2720
+                if (empty($subscription_meta['trial_interval'])) {
2721 2721
                     $subscription_meta['trial_interval'] = $item->get_trial_interval();
2722 2722
                 }
2723 2723
             } else {
2724 2724
                 $subscription_meta['trial_period']      = '';
2725 2725
                 $subscription_meta['trial_interval']    = 0;
2726 2726
             }
2727
-            if ( !$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0 ) {
2727
+            if (!$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0) {
2728 2728
                 $subscription_meta['bill_times'] = $item->get_recurring_limit();
2729 2729
             }
2730
-            if ( $subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '' ) {
2731
-                $subscription_meta['initial_amount']    = wpinv_format_amount( $this->get_total() );
2732
-                $subscription_meta['recurring_amount']  = wpinv_format_amount( $this->get_recurring_details( 'total' ) );
2730
+            if ($subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '') {
2731
+                $subscription_meta['initial_amount']    = wpinv_format_amount($this->get_total());
2732
+                $subscription_meta['recurring_amount']  = wpinv_format_amount($this->get_recurring_details('total'));
2733 2733
             }
2734 2734
         }
2735 2735
         
2736
-        if ( $filed === '' ) {
2737
-            return apply_filters( 'wpinv_get_invoice_subscription_data', $subscription_meta, $this );
2736
+        if ($filed === '') {
2737
+            return apply_filters('wpinv_get_invoice_subscription_data', $subscription_meta, $this);
2738 2738
         }
2739 2739
         
2740
-        $value = isset( $subscription_meta[$filed] ) ? $subscription_meta[$filed] : '';
2740
+        $value = isset($subscription_meta[$filed]) ? $subscription_meta[$filed] : '';
2741 2741
         
2742
-        return apply_filters( 'wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this );
2742
+        return apply_filters('wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this);
2743 2743
     }
2744 2744
     
2745 2745
     public function is_paid() {
2746
-        if ( $this->has_status( array( 'publish', 'complete', 'processing', 'renewal' ) ) ) {
2746
+        if ($this->has_status(array('publish', 'complete', 'processing', 'renewal'))) {
2747 2747
             return true;
2748 2748
         }
2749 2749
         
@@ -2755,28 +2755,28 @@  discard block
 block discarded – undo
2755 2755
         
2756 2756
         $requires_vat = false;
2757 2757
         
2758
-        if ( $this->country ) {
2758
+        if ($this->country) {
2759 2759
             $wpi_country        = $this->country;
2760 2760
             
2761
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2761
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2762 2762
         }
2763 2763
         
2764
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2764
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2765 2765
     }
2766 2766
     
2767 2767
     public function refresh_item_ids() {
2768 2768
         $item_ids = array();
2769 2769
         
2770
-        if ( !empty( $this->cart_details ) ) {
2771
-            foreach ( $this->cart_details as $key => $item ) {
2772
-                if ( !empty( $item['id'] ) ) {
2770
+        if (!empty($this->cart_details)) {
2771
+            foreach ($this->cart_details as $key => $item) {
2772
+                if (!empty($item['id'])) {
2773 2773
                     $item_ids[] = $item['id'];
2774 2774
                 }
2775 2775
             }
2776 2776
         }
2777 2777
         
2778
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2778
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2779 2779
         
2780
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2780
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2781 2781
     }
2782 2782
 }
Please login to merge, or discard this patch.